博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2020-1024---商品倒计时
阅读量:3960 次
发布时间:2019-05-24

本文共 2288 字,大约阅读时间需要 7 分钟。

效果

三个商品不同的倒计时
在这里插入图片描述
html代码

    
stoptime
  • 2199
    • ¥3298.00
  • 3499
    • ¥3499.00
  • 38.5
    • ¥160.00

css代码

ul li{
width: 400px; border: 1px solid black; list-style: none; color: white; float: left;}img{
display:block; margin: 0 auto;}.box .bg{
width: 400px; height: 55px; background: url('./img/logo.png') no-repeat 4px 2px;}.box ul li span{
float: left; font-size: 20px; width: 100px;}.box ul li span b{
font-size: 46px; font-weight: 100;}.box ul li .time{
float: right; width: 280px; margin: 4px 0; border: none; font-size: 14px;}.box ul li .time:first-child{
text-decoration: line-through;}

jq代码

function timer(selector,time1){
setInterval(() => {
var now_date = new Date(); var now_time = now_date.getTime(); var new_data = new Date(time1); var new_time = new_data.getTime(); var time = new_time - now_time; var day = Math.floor(time / 24 / 60 / 60 / 1000); var hour = Math.floor((time - (day * 24 * 60 *60 * 1000)) / (60 * 60 * 1000)); var min = Math.floor((time - (day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000)) / (60 * 1000)) var sed = Math.floor((time / 1000 ) % 60); $(selector).text('距离结束 : ' + double(day) + '天' + double(hour) + '时' + double(min) + '分' + double(sed) + '秒'); }, 0)}function double(t){
if(parseInt(t / 10) < 1){
t = '0' + t; return t; }else{
return t; }} timer('.bg .t1','2020-10-28,12:00:00');timer('.bg .t2','2020-11-28,12:00:00');timer('.bg .t3','2020-12-28,12:00:00');

转载地址:http://itqzi.baihongyu.com/

你可能感兴趣的文章