欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

新百胜娱乐公司_17665445111

程序员文章站 2022-05-10 17:26:02
...

www.xbs1567.com这篇文章主要为大家详细介绍了JavaScript实现钟表案例,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了JavaScript实现钟表效果的具体代码,供大家参考,具体内容如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. .clock {
  10. width: 600px;
  11. height: 600px;
  12. margin: 100px auto;
  13. background: url(/image/shizhong.jpg) 600px/600px;
  14. position: relative;
  15. }
  16. .clock .h {
  17. width: 100%;
  18. height: 100%;
  19. background: url(/image/时针.jpg) no-repeat center center;
  20. background-size: 35px;
  21. z-index: 1;
  22. position: absolute;
  23. left: -3px;
  24. top: -60px;
  25. }
  26. .clock .m {
  27. width: 100%;
  28. height: 100%;
  29. background: url(/image/分针.jpg) no-repeat center center;
  30. background-size: 35px;
  31. z-index: 2;
  32. position: absolute;
  33. left: -3px;
  34. top: -95px;
  35. }
  36. .clock .s {
  37. width: 100%;
  38. height: 100%;
  39. background: url(/image/秒针.jpg) no-repeat center center;
  40. background-size: 25px;
  41. z-index: 3;
  42. position: absolute;
  43. left: -3px;
  44. top: -95px;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div class="clock">
  50. <div class="h" id="hour"></div>
  51. <div class="m" id="min"></div>
  52. <div class="s" id="second"></div>
  53. </div>
  54. </body>
  55. <script>
  56. var h = document.querySelector(".h")
  57. var m = document.querySelector(".m")
  58. var s = document.querySelector(".s")
  59. var s = m = h = ms = 0;
  60. setInterval(function () {
  61. var date = new Date()
  62. ms = date.getMilliseconds()/* 现在的毫秒 */
  63. s = date.getSeconds() + ms / 1000;
  64. m = date.getMinutes() + s / 60;
  65. h = date.getHours() % 12 + m / 60;
  66. /*秒针一圈360度 一共60秒 每秒6度 */
  67. second.style.transform = "rotate(" + s * 6 + "deg)"
  68. second.style.transformOrigin = ' center 67% '
  69. /*分针一圈360度 一圈走60次 每分钟6度 */
  70. min.style.transform = "rotate(" + m * 6 + "deg)"
  71. min.style.transformOrigin = ' center 67% '
  72. /*时针一圈360度 12小时制 一共走12次 d 每小时30度 */
  73. hour.style.transform = "rotate(" + h * 30 + "deg)"
  74. hour.style.transformOrigin = ' center 60% '
  75. },30)
  76. </script>
  77. </html>

效果:
新百胜娱乐公司_17665445111
以上就是本文的全部内容,希望对大家的学习有所帮助