下面小编就为大家带来一篇 JS 实现倒计时数字时钟效果【附实例代码】。小编觉得挺不错的,现在分享给大家,也给大家做一个参考。
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
这篇文章主要介绍了 JS 实现的网页倒计时数字时钟效果, 是一款非常实用的 javascript 倒计时特效, 具有一定参考借鉴价值, 需要的朋友可以参考下
本文实例讲述了 JS 实现的网页倒计时数字时钟效果。分享给大家供大家参考。具体实现方法如下:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>
- javascript实现的倒计时时钟
- </title>
- <style>
- body,div{margin:0;padding:0;} body{color:#fff;font:16px/1.5 \5fae\8f6f\96c5\9ed1;}
- #countdown{width:300px;text-align:center;background:#1a1a1a;margin:10px
- auto;padding:20px 0;} input{border:0;width:283px;height:50px;cursor:pointer;margin-top:20px;background:url(http://www.phperz.com/jsCSS/demoimg/201210/btn-1.png)
- no-repeat;} input.cancel{background-position:0 -50px;} span{color:#000;width:80px;line-height:2;background:#fbfbfb;border:2px
- solid #b4b4b4;margin:0 10px;padding:0 10px;}
- </style>
- <script>
- window.onload = function() {
- var oCountDown = document.getElementById("countdown");
- var aInput = oCountDown.getElementsByTagName("input")[0];
- var timer = null;
- aInput.onclick = function() {
- this.className == "" ? (timer = setInterval(updateTime, 1000), updateTime()) : (clearInterval(timer));
- this.className = this.className == '' ? "cancel": '';
- };
- function format(a) {
- return a.toString().replace(/^(\d)$/, '0$1')
- }
- function updateTime() {
- var aSpan = oCountDown.getElementsByTagName("span");
- var oRemain = aSpan[0].innerHTML.replace(/^0/, '') * 60 + parseInt(aSpan[1].innerHTML.replace(/^0/, ''));
- if (oRemain <= 0) {
- clearInterval(timer);
- return
- }
- oRemain--;
- aSpan[0].innerHTML = format(parseInt(oRemain / 60));
- oRemain %= 60;
- aSpan[1].innerHTML = format(parseInt(oRemain));
- }
- }
- </script>
- </head>
- <body>
- <div id="countdown">
- <span>
- 01
- </span>
- 分钟
- <span>
- 40
- </span>
- 秒
- <input type="button" value="" />
- </div>
- 码农教程 www.manongjc.com 代码特效
- </body>
- </html>
以上这篇 JS 实现倒计时数字时钟效果【附实例代码】就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持 phperz。
来源: http://www.phperz.com/article/17/0221/266492.html