原生js实现可爱糖果数字时间特效

效果展示:http://demo.jb51.net/js/2016/js_hovertreecolortime/

源码下载:http://xiazai.jb51.net/201612/yuanma/hovertreecolortime_jb51.rar

数字采用漂亮的糖果皮肤设计

效果图:

代码如下:

<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1" />
 <title>js多彩的数字时钟_何问起</title><base target="_blank" />
 <style>a{color:blue;}</style>
</head>
<body>
 <div><h1>JS实现多彩的数字时钟</h1></div>
 <div id="time"></div>
 <div><br /><br /><a href="http://hovertree.com">何问起</a> <a href="http://hovertree.com/h/bjaf/o0yqj1ly.htm">说明</a> <a href="http://hovertree.com/texiao/">特效</a></div>
 <script>
 function getTime(){
 var date = new Date();
 var hours =formatTime(date.getHours());
 var minutes = formatTime(date.getMinutes());
 var seconds = formatTime(date.getSeconds());
 var $time = document.getElementById('time');
 $time.innerHTML=hours +"<img src='images/hm.png' style='margin:0 10px;' width='12' height='40'/>"+ minutes+"<img style='margin:0 10px;' src='images/ms.png' width='12' height='40'/>"+ seconds;
 setTimeout("getTime()",500);
 }
 function formatTime(i){
 if(i<10&&i==1){
  i= "<img src='images/0.png' width='40' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>";
 }else if(i<10&&i!=1){
  i= "<img src='images/0.png' width='40' height='60'/>" + "<img src='images/"+i+".png' width='40' height='60'/>";
 }else{
  var j= i.toString().charAt(0);
  var z =i.toString().charAt(1);
  if(j<10 && z<10&&j!=1&&z!=1){
  i = "<img src='images/"+j+".png' width='40' height='60'/>" + "<img src='images/"+z+".png' width='40' height='60'/>";
  }else if(j<10 && z<10&&j==1&&z!=1){
  i = "<img src='images/1.png' width='20' height='60'/>" + "<img src='images/"+z+".png' width='40' height='60'/>";
  }else if(j<10 && z<10&&z==1&&j!=1){
   i = "<img src='images/"+j+".png' width='40' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>";
  }else if(j<10 && z<10&&(j==1&&z==1)){
  i="<img src='images/1.png' width='20' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>";
  }
 }
 return i;
 }
 getTime();
 </script>
</body>
</html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持呐喊教程!

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。