JS实现秒杀倒计时特效
人气:0知识点
添加一个定时器,对时间标签不断进行更新设置即可。
引入工具库工具库
运行效果
代码
引入MyTool.js
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ font-size: 30px; } span{ background-color: #000; color: #fff; border-radius: 10px; padding: 0 5px; } </style> </head> <body> <div id="box"> <span>00</span>:<span>00</span>:<span>00</span> </div> <script src="../00MyTools/MyTools.js"></script> <script> window.addEventListener('load',function (ev) { var hour = myTool.$('box').children[0], min = myTool.$('box').children[1], sec = myTool.$('box').children[2]; var time = 8 * 60 * 60; var timer = setInterval(function () { time--; hour.innerText = myTool.addZero(myTool.secondToHourMinSecond(time).hour); min.innerText = myTool.addZero(myTool.secondToHourMinSecond(time).min); sec.innerText = myTool.addZero(myTool.secondToHourMinSecond(time).second); if (time===0){ clearInterval(timer); } },1000); },false); </script> </body> </html>
您可能感兴趣的文章:
加载全部内容