【JS】倒计时

时间:2022-05-08 21:13:41

描述:

先要链接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\" onclick=\"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);