This article describes the JS countdown to the simple implementation of the code, sharing for everyone to reference, specific as follows:
function Timedown (second) {
var month = ', day = ', hour = ', Minute = ';
if (second >= 86400 *) {
month = Math.floor (Second/(86400 * 30)) + ' month ';
Second = second% (86400 *);
}
if (second >= 86400) {
day = Math.floor (second/86400) + ' days ';
Second = second% (86400);
}
if (second >= 3600) {
hour = Math.floor (second/3600) + ' hour ';
Second = second% 3600;
}
if (second >=) {
minute = Math.floor (second/60) + ' min ';
Second = second%;
if (Second > 0) {
second = second? Second + ' seconds ': ';
}
Return month + day + hour + minute + second;
}
If you want to display the countdown effect, you can use the following code to call:
<!--introduce jquery-->
<script>
$ (function () {
var second = 10000;
$ ('. Remain_time '). HTML (Timedown (second));
SetInterval (function () {
second--;
$ ('. Remain_time '). HTML (Timedown (second);
}, 1000);
})
</script>
<span class= "Remain_time" ></span>
jquery Plug-in form:
$.fn.timedown = function (opt) {var second = Opt.second;
var tip = ' expired ';
var $this = this;
Self._timedown = function (second) {var month = ', day = ', hour = ', Minute = ';
if (second >= 86400 *) {month = Math.floor (Second/(86400 * 30)) + ' month ';
Second = second% (86400 * 30);
} if (second >= 86400) {day = Math.floor (second/86400) + ' days ';
Second = second% (86400);
} if (second >= 3600) {hour = Math.floor (second/3600) + ' hour ';
Second = second% 3600;
} if (second >=) {minute = Math.floor (second/60) + ' min ';
Second = second% 60;
} if (Second > 0) {second = second? Second + ' seconds ': ';
else {return tip;
Return to month + day + hour + minute + second;
};
$this. HTML (Self._timedown (second));
SetInterval (function () {second--;
$this. HTML (Self._timedown (second));
}, 1000)}; How to use $('. Remain_time '). Timedown ({second:1000,tip: ' Expired '})
I hope this article will help you with your JavaScript programming.