废话不多说,直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
body,ul{margin:0;padding: 0;}
.content{margin:100px auto;width: 1000px;}
.box{position: relative;float: left;width: 50px;height: 120px;overflow: hidden;}
.box li{position: absolute;left: 0;width:100%;height: 120px;list-style:none;font-size:80px;font-weight: bold;background-color: #fff; line-height: 120px; text-align: center;}
.colon{float: left;height: 120px;font-size: 80px;color: #e91e63;font-weight: bold;line-height: 100px;}
</style>
</head>
<body>
<div class="content">
</div>
<script type="text/javascript">
(function(){
var colors = ["#69D2E7", "#E20049", "#19215E", "#F38630", "#FA6900", "#FF4E50", "#F9D423", "#FFB6FF", "#474168", "#6ACAFC"];
var content = document.querySelector('.content');
var num = 0;
var height = 120;
var maxheight = (2-num)*height;
var timeNum = [3,10,6,10,6,10];
var position = [];
var NumberBoxs = [];
for(var i =0;i<10;i++){
position.push((1-i)*height);
};
function NumberBox() {}
NumberBox.prototype = {
init : function () {
var innerHTML = "<div class='box' id='box"+num+"'><ul>"
this.num = num;
num++;
for(var i =0,l=timeNum[this.num];i<l;i++){
innerHTML += "<li style='color:"+colors[i]+"'>"+i+"</li>";
}
innerHTML += "</ul><div>"
content.innerHTML += innerHTML;
if(num==2||num==4){content.innerHTML += "<div class='colon'>:</div>"}
},
dominit : function(){
this.Ali = [].slice.call(document.getElementById('box'+this.num).getElementsByTagName('li'),0);
this.Ali.forEach(function(dom,i){
dom.style.top = position[i] + "px";
dom.style.transition = "top .8s";
})
this.hasdom = true;
},
toNum : function (n) {
if(!this.hasdom){this.dominit();}
n = ""+n;
var p = this;
var l = p.Ali.length-1;
while(p.Ali[1].innerHTML!=n){
p.Ali.unshift(p.Ali.pop());
}
p.Ali.forEach(function (dom,i) {
dom.style.zIndex = (i==l)"-1":"1";
dom.style.top = position[i] + "px";
})
}
}
for(var i=0;i<6;i++){
var o = new NumberBox();
o.init();
NumberBoxs.push(o);
}
function getTime() {
var time = new Date();
return (""+Fixed2(time.getHours())+Fixed2(time.getMinutes())+Fixed2(time.getSeconds())).split("");
}
function Fixed2(n){
return Number(n)<10"0"+n:n;
}
(function () {
var time = getTime();
NumberBoxs.forEach(function(obj,i){
obj.toNum(time[i]);
});
setTimeout(arguments.callee,1000);
})()
})();
</script>
</body>
</html>
以上这篇js数字滑动时钟的简单实现(示例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
js数字滑动时钟
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“js数字滑动时钟的简单实现(示例讲解)”评论...
更新日志
2025年10月24日
2025年10月24日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]