码迷,mamicode.com
首页 > Web开发 > 详细

js倒计时

时间:2015-11-11 11:20:59      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

         1.第一种
           //退订倒计时
            timeOut:function(nowDay,endDay){

                var timeLeave = (endDay - nowDay) / 1000,

                    interval = 0;

                interval = setInterval(function() {

                    intervalTime();

                }, 1000);

                function intervalTime() {

                    var J_day = $(".J-day"),

                        J_hour = $(".J-hour"),

                        J_minute = $(".J-minute"),

                        J_second = $(".J-second");

                    if (timeLeave > 0) {

                        var day = Math.floor(timeLeave / (24 * 60 * 60)),

                            hour = Math.floor(timeLeave % (24 * 60 * 60) / (60 * 60)),

                            minute = Math.floor(timeLeave % (24 * 60 * 60) % (60 * 60) / 60),

                            second = Math.floor(timeLeave % (24 * 60 * 60) % (60 * 60) % 60);

                        J_day.html(day);
                        J_hour.html(hour);
                        J_minute.html(minute);
                        J_second.html(second);

                        timeLeave--;

                    } else {

                        clearInterval(interval);

                        J_day.html("0");
                        J_hour.html("0");
                        J_minute.html("0");
                        J_second.html("0");

                        $(".J-to-tip").html("请尽快填写退货物流信息,方便商家为您处理退款");

                    }

                }

            }
 
     2.第二种
     (function($) {

    function TimeOut(endDay) {
        var tDay = new Date(),
            //yearNow = tDay.getFullYear(),
            //dayNow = tDay.getDate(),
            //endDay = new Date(yearNow, 10, dayNow+6, 23, 59, 59)
            timeLeave = (endDay - tDay) / 1000;
        var day = Math.floor(timeLeave / (24 * 60 * 60)),
            hour = Math.floor(timeLeave % (24 * 60 * 60) / (60 * 60)),
            minute = Math.floor(timeLeave % (24 * 60 * 60) % (60 * 60) / 60),
            second = Math.floor(timeLeave % (24 * 60 * 60) % (60 * 60) % 60);

        $(".J-day").html(day);
        $(".J-hour").html(hour);
        $(".J-minute").html(minute);
        $(".J-second").html(second);
    }

    var dayNow = new Date(2015,11,25,08,00,00),
        yearNow = dayNow.getFullYear(),
        monthNow = dayNow.getMonth(),
        dayNow = dayNow.getDate(),
        endDay = new Date(yearNow, monthNow, dayNow + 10, 23, 59, 59);
    console.log(endDay.getTime());
    setInterval(function() {
        TimeOut(endDay);
    }, 1000);


})(jQuery);

js倒计时

标签:

原文地址:http://www.cnblogs.com/jiet/p/4955314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!