HTML5超酷秒表动画 可暂停和重置秒表

关于HTML5CSS3的时钟应用在之前我们已经分享过不少了,还有一些HTML5的日期选择应用。今天我们要分享一款基于HTML5和CSS3的圆盘秒表动画,秒表可以精确到0.001秒,并且可以在计时过程中暂停计时,同时秒表可以随时重置。


11.png




下面来分析一下实现的源代码,主要由HTML和CSS代码组成,CSS相对比较复杂,因为涉及到动画。


HTML代码:


  1. <input id="help" name="controls" type="checkbox" />
  2.   <input id="settings" name="controls" type="checkbox" />

  3.   <input id="orange"  name="color" type="radio"  />
  4.   <input id="green"  name="color" type="radio" checked="checked" />

  5.   <div>

  6.     <input id="start" name="controls" type="radio" />
  7.     <input id="stop" name="controls" type="radio" />
  8.     <input id="reset" name="controls" type="radio" />

  9.     <div>
  10.       <div>
  11.         <div>
  12.         </div>
  13.       </div>

  14.       <div>
  15.         <div>
  16.           <div>
  17. 1 2 3 4 5 6 7 8 9
  18.           </div>
  19.         </div>
  20.         <div>
  21.           <div>
  22. 1 2 3 4 5 6 7 8 9
  23.           </div>
  24.         </div>
  25.         <div>
  26.           :
  27.         </div>

  28.         <div>
  29.           <div>
  30. 1 2 3 4 5
  31.           </div>
  32.         </div>
  33.         <div>
  34.           <div>
  35. 1 2 3 4 5 6 7 8 9
  36.           </div>
  37.         </div>
  38.         <div>
  39.           :
  40.         </div>

  41.         <div>
  42.           <div>
  43. 1 2 3 4 5
  44.           </div>
  45.         </div>
  46.         <div>
  47.           <div>
  48. 1 2 3 4 5 6 7 8 9
  49.           </div>
  50.         </div>
  51.         <div>
  52.           :
  53.         </div>

  54.         <div>
  55.           <div>
  56. 1 2 3 4 5 6 7 8 9
  57.           </div>
  58.         </div>
  59.         <div>
  60.           <div>
  61. 1 2 3 4 5 6 7 8 9
  62.           </div>
  63.         </div>
  64.         <div>
  65.           <div>
  66. 1 2 3 4 5 6 7 8 9
  67.           </div>
  68.         </div>

  69.       </div>

  70.       <div>
  71.         <label id="haptic" for="stop">
  72.         </label>
  73.         <label id="haptic2" for="start">
  74.         </label>
  75.         <label id="haptic3" for="reset">
  76.         </label>

  77.       </div>

  78.     </div>

  79.   </div>
复制代码


这里主要是定义了圆盘时钟的基本结构,以及开始、暂停和复位按钮。接下来重点是CSS代码:


CSS代码:


首先来定义一些动画:



  1. @-webkit-keyframes start_haptic {from { -webkit-transform:scale(.98)}to {}}
  2. @-webkit-keyframes stop_haptic {from { -webkit-transform:scale(.98)}to {}}
  3. @-webkit-keyframes reset_haptic {from { -webkit-transform:scale(.98)}to {}}

  4. @-webkit-keyframes launch {from { -webkit-transform:scale(1.2); opacity:0} to {}}
  5. @-webkit-keyframes info {from { -webkit-transform:scale(.8) translateY(100px); opacity:0} to {}}
  6. @-webkit-keyframes menu {from { -webkit-transform:scale(.9) translateY(-50px); opacity:0} to {}}

  7. @-webkit-keyframes reset {from {-webkit-transform:rotateZ(180deg);} 60%{ -webkit-transform:rotateZ(-30deg);} 70%{ -webkit-transform:rotateZ(10deg);} 80%{ -webkit-transform:rotateZ(-10deg);}to { -webkit-transform:rotateZ(0);}}

  8. @-webkit-keyframes arrow { from  { -webkit-transform: rotateZ(0deg);}to{-webkit-transform: rotateZ(360deg)}}
  9. @-webkit-keyframes sec{ from  { top:0px;}to{top:-300px;}}
  10. @-webkit-keyframes sec1{ from  { top:0px;}to{top:-180px;}}
复制代码


再将这些动画在各个按钮被激活时启用这些动画:


  1. .start:checked~.container .mil0{-webkit-animation-play-state:running;}
  2. .stop:checked~.container .mil0{-webkit-animation-play-state:paused;}
  3. .start:checked~.container .mil{-webkit-animation-play-state:running;}

  4. .stop:checked~.container .mil{-webkit-animation-play-state:paused;}
  5. .start:checked~.container .mil1{-webkit-animation-play-state:running;}
  6. .stop:checked~.container .mil1{-webkit-animation-play-state:paused;}

  7. .reset:checked~.container .mil1{-webkit-animation:none;top:0;transition:.2s;}
  8. .reset:checked~.container .mil0{-webkit-animation:none;top:0;transition:.2s;}
  9. .reset:checked~.container .mil{-webkit-animation:none;top:0;transition:.2s;}

  10. .start:checked~.container .sec{-webkit-animation-play-state:running;}
  11. .stop:checked~.container .sec{-webkit-animation-play-state:paused;}
  12. .reset:checked~.container .sec{-webkit-animation:none;top:0;transition:.2s;}

  13. .start:checked~.container .sec1{-webkit-animation-play-state:running;}
  14. .stop:checked~.container .sec1{-webkit-animation-play-state:paused;}
  15. .reset:checked~.container .sec1{-webkit-animation:none;top:0;transition:.2s;}

  16. .start:checked~.container .min{-webkit-animation-play-state:running;}
  17. .stop:checked~.container .min{-webkit-animation-play-state:paused;}
  18. .reset:checked~.container .min{-webkit-animation:none;top:0;transition:.2s;}

  19. .start:checked~.container .min1{-webkit-animation-play-state:running;}
  20. .stop:checked~.container .min1{-webkit-animation-play-state:paused;}
  21. .reset:checked~.container .min1{-webkit-animation:none;top:0;transition:.2s;}

  22. .start:checked~.container .arrow{-webkit-animation-play-state:running;}
  23. .stop:checked~.container .arrow{-webkit-animation-play-state:paused;}
  24. .reset:checked~.container .arrow{-webkit-animation:reset  .4s; -webkit-animation-fill-mode:forwards;}

  25. .controls{ height:60px;width:200px;margin:0 auto;  position:relative;  }

  26. .stop_,.start_{position:absolute; z-index:3; height:60px; width:80px; left:60px; transition:.2s; background-position:center center;background-repeat:no-repeat;}
复制代码


最后将源代码一并附上,下载地址>>

源码下载
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值