/** * 倒计时 Create By TuJia @2017.10.17 * 使用方法: * leftTimer.run(container[,theme][,callback]); * * 支持 jQuery选择器 及 原生选择器(不依赖jQuery) * * 示例(jquery 选择器): * leftTimer.run($('.countdown')); * leftTimer.run($('.countdown'), 'D天H时M分S秒'); * leftTimer.run($('.countdown'), 'D天H时M分S秒', function(obj){ * // do some things * // obj.html('已结束'); 或 location.reload(); * }); * * 示例(原生选择器): * leftTimer.run(document.querySelectorAll('.countdown')); * leftTimer.run(document.querySelectorAll('.countdown'), 'D天H时M分S秒'); * leftTimer.run(document.querySelectorAll('.countdown'), 'D天H时M分S秒', function(obj){ * // do some things * // obj.innerHTML = '已结束'; 或 location.reload(); * }); */var leftTimer = { startTime:0, count:0, interval:1000, oneday:3600 * 24, str:'', day:0, hour:0, minute:0, second:0, show_day:false, show_hour:false, show_minute:false, show_second:false, offset:0, next_time:0, run:function(container, theme, cb){ var scope = this; scope.startTime = new Date().getTime(); scope.next_time = scope.interval; scope.count = 0; scope.offset = 0; theme = theme || "D天H时M分S秒"; cb = cb || function(){ location.reload() }; scope.show_day = theme.indexOf('D')!=-1; scope.show_hour = theme.indexOf('H')!=-1; scope.show_minute = theme.indexOf('M')!=-1; scope.show_second = theme.indexOf('S')!=-1; for(var i=0,len=container.length; i
Git 地址: