js 实现倒计时特效

<div id="tiao" style="width:559px; height:300px;"></div>

<!--脚本开始-->

<script language="javascript" type="text/javascript">

countDown(3);

function countDown(secs){

/* document.getElementById("tiao").style.backgroundImage="url(/tpl/Wap/default/common/xinnian/decode"+secs+".png)"; 

*/

 document.getElementById("tiao").innerHTML=secs;

 if(--secs>0)

  setTimeout("countDown("+secs+")",1000);

 }

 </script>



本文转自 gutaotao1989 51CTO博客,原文链接:http://blog.51cto.com/taoyouth/1613995

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用HTML和JavaScript实现的新年倒计时特效的示例: ```html <!DOCTYPE html> <html> <head> <title>New Year Countdown</title> <style> .countdown { font-size: 48px; text-align: center; margin-top: 200px; } </style> </head> <body> <div class="countdown" id="countdown"></div> <script> // 设置倒计时的目标日期和时间 var countDownDate = new Date("Jan 1, 2023 00:00:00").getTime(); // 每秒更新倒计时 var countdown = setInterval(function() { // 获取当前时间 var now = new Date().getTime(); // 计算距离目标日期的时间差 var distance = countDownDate - now; // 计算剩余的天、小时、分钟和秒 var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // 在页面上显示倒计时 document.getElementById("countdown").innerHTML = days + "天 " + hours + "小时 " + minutes + "分钟 " + seconds + "秒"; // 如果倒计时结束,则显示提示信息 if (distance < 0) { clearInterval(countdown); document.getElementById("countdown").innerHTML = "新年快乐!"; } }, 1000); </script> </body> </html> ``` 这个示例中,我们使用了HTML和CSS来创建一个居中显示的倒计时文本框。然后,使用JavaScript来计算当前时间与目标日期之间的时间差,并更新倒计时文本框的内容。当倒计时结束时,将显示"新年快乐!"的提示信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值