【JS】倒计时

描述:

先要链接jquery.js,这样写法可以直接放JS文件运行。

//放在图片里定位的倒计时

//顶图里面定位才使用的代码
document.writeln("<style>");
document.writeln("    .top_div1{width:100%;overflow:hidden;margin:0 auto;text-align:center;}");
document.writeln("    .top_div2{");
document.writeln("    text-align:center;max-width:1600px;margin:0 auto;text-align:center;background: url(/images/headerPic.jpg) no-repeat center;height:200px;");
document.writeln("    }    ");
document.writeln("    .top_div3{");
document.writeln("    height:100px;width:100px;position:absolute;right:245px;top:40px;float:right;");
document.writeln("    }");
document.writeln("    </style>");
document.writeln(" <div class=\"top_div1\">");
document.writeln(" <a href=\"/hd_tex.html\" οnclick=\"gaPush(\'top_huodong_banner\'); _czc.push([\'_trackEvent\', \'swt\', \'top_huodong_banner\', \'top_huodong_banner\', 0, \'top_huodong_banner\']);\" target=\"_blank\">");
document.writeln(" <div class=\"top top_div2\">");
document.writeln(" <div id=\"div_dw\" class=\"top_div3\">");
document.writeln(" <div id=\"lastDays1\" style=\"color:red;font-size:95px;font-weight: bold;line-height:70px;height:70px;margin-top:5px;font-family:黑体\"></div>");
document.writeln(" <div style=\"font-size:10px;color:#000;margin-top:10px; margin-left:10px;\"><span id=\"lastHours1\">12</span>小时<span id=\"lastMin1\">23</span>分<span id=\"lastSecond1\">0</span>秒</div>    ");
document.writeln(" </div>");
document.writeln(" </div>");
document.writeln(" </a>");
document.writeln(" </div>");

//以屏宽1424为准的计算
var juli = 245 + ($(window).width() - 1424)/2;
$("#div_dw").css("right",juli);
//顶图倒计时
function ShowTOPDown(year,month,day) 
{ 
var now = new Date(); 
var endDate = new Date(year, month-1, day); 
var leftTime=endDate.getTime()-now.getTime(); 
var leftsecond = parseInt(leftTime/1000); 
//var day1=parseInt(leftsecond/(24*60*60*6)); 
var day1=Math.floor(leftsecond/(60*60*24)); 
var hour=Math.floor((leftsecond-day1*24*60*60)/3600); 
var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60); 
var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
$("#lastDays1").html(day1);
$("#lastHours1").html(hour);
$("#lastMin1").html(minute);
$("#lastSecond1").html(second);
}
window.setInterval(function(){ShowTOPDown(2016,01,02);}, 1000);

 

转载于:https://www.cnblogs.com/laokchen/p/5752088.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值