js倒計時

          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);
相關文章
相關標籤/搜索