时间倒计时插件

来源:互联网 发布:含氟牙膏推荐 知乎 编辑:程序博客网 时间:2024/05/17 07:30

时间倒计时插件

效果:


源码:

<div class="share_message_time pt_time"  data-actime="2017-09-13 00:00:00" data-time="2017-09-05 19:40:30">    剩    <span class="hours time">05</span>:    <span class="minute time">10</span>:    <span class="second time">30</span>    结束</div>

//时间倒计时插件$.fn.ptTime = function() {    return this.each(function(e) {    var that=$(this);    var end_time=$(this).attr("data-time");//时间格式:2017.9.07 13:30    var end_act_time=$(this).attr("data-acTime");//时间格式:2017.9.07 13:30    var timestamp2 = Date.parse(new Date(end_time)); //结束时间            end_time = timestamp2 / 1000;        var timestamp1=Date.parse(new Date(end_act_time));  //活动结束时间            end_act_time= timestamp1 / 1000;        var  timestamp3 =  Math.round(new Date().getTime()/1000);  //现在的时间        if(timestamp3<end_act_time){    setInterval(function(){            var  now_time =  Math.round(new Date().getTime()/1000);  //现在的时间            var time =end_time - now_time;            var hour = parseInt(time / 60 / 60 );            var minute = parseInt(time / 60 % 60);            var seconds = parseInt(time % 60);            if(now_time<= end_time){            if(hour < 10){                 hour = "0" + hour;             }             if(minute < 10){                 minute = "0" + minute;             }             if(seconds < 10){                seconds = "0" + seconds;             }            that.find(".hours").text(hour).end().find(".minute").text(minute).end().find(".second").text(seconds);            }        },1000);    }    })};


原创粉丝点击