• 翻页-时钟


    1. <html>
    2. <head>
    3. <style>
    4. .seconds,
    5. .hours,
    6. .minutes {
    7. position: relative;
    8. }
    9. .base {
    10. width: 130px;
    11. height: 100px;
    12. overflow: hidden;
    13. }
    14. .text {
    15. text-align: center;
    16. font-size: 100px;
    17. font-weight: 900;
    18. color: #fff;
    19. }
    20. .top {
    21. line-height: 200px;
    22. border-radius: 4px 4px 0 0;
    23. background-color: #333;
    24. }
    25. .bottom {
    26. line-height: 0;
    27. border-radius: 0 0 4px 4px;
    28. background-color: #333;
    29. }
    30. .flip {
    31. position: absolute;
    32. top: 0;
    33. transform-origin: bottom;
    34. border-radius: 4px 4px 0 0;
    35. z-index: 1;
    36. }
    37. .flip-face {
    38. position: absolute;
    39. z-index: 1;
    40. background-color: #333;
    41. line-height: 200px;
    42. }
    43. .flip-back {
    44. position: absolute;
    45. background-color: #333;
    46. line-height: 0;
    47. transform: perspective(500px) rotateX(0deg) rotateY(-180deg) rotate(180deg);
    48. }
    49. .times{
    50. width: 400px;
    51. display: flex;
    52. justify-content: space-between;
    53. }
    54. </style>
    55. </head>
    56. <body>
    57. <div class="times">
    58. <div class="hours" id="hours">
    59. <div class="top base text" id="htop">0</div>
    60. <div class="flip base" id="hflip">
    61. <div class="flip-face base text" id="hflip-face">0</div>
    62. <div class="flip-back base text" id="hflip-back">0</div>
    63. </div>
    64. <div class="bottom base text" id="hbottom">0</div>
    65. </div>
    66. <div class="minutes" id="minutes">
    67. <div class="top base text" id="mtop">0</div>
    68. <div class="flip base" id="mflip">
    69. <div class="flip-face base text" id="mflip-face">0</div>
    70. <div class="flip-back base text" id="mflip-back">0</div>
    71. </div>
    72. <div class="bottom base text" id="mbottom">0</div>
    73. </div>
    74. <div class="seconds" id="seconds">
    75. <div class="top base text" id="top">0</div>
    76. <div class="flip base" id="flip">
    77. <div class="flip-face base text" id="flip-face">0</div>
    78. <div class="flip-back base text" id="flip-back">0</div>
    79. </div>
    80. <div class="bottom base text" id="bottom">0</div>
    81. </div>
    82. </div>
    83. <script>
    84. //seconds
    85. const seconds = document.querySelector('#seconds')
    86. const Top = seconds.querySelector('#top')
    87. const flip = seconds.querySelector('#flip')
    88. const flipFace = flip.querySelector('#flip-face')
    89. const flipBack = flip.querySelector('#flip-back')
    90. const bottom = seconds.querySelector('#bottom')
    91. let timer = null, stimer = null, mtimer = null, htimer = null
    92. //minutes
    93. const minutes = document.querySelector('#minutes')
    94. const mTop = minutes.querySelector('#mtop')
    95. const mflip = minutes.querySelector('#mflip')
    96. const mflipFace = mflip.querySelector('#mflip-face')
    97. const mflipBack = mflip.querySelector('#mflip-back')
    98. const mbottom = minutes.querySelector('#mbottom')
    99. //hours
    100. const hours = document.querySelector('#hours')
    101. const hTop = hours.querySelector('#htop')
    102. const hflip = hours.querySelector('#hflip')
    103. const hflipFace = hflip.querySelector('#hflip-face')
    104. const hflipBack = hflip.querySelector('#hflip-back')
    105. const hbottom = hours.querySelector('#hbottom')
    106. const oneCycle = (time, timer) => {
    107. const seconds = time.seconds
    108. const minutes = time.minutes
    109. const hours = time.hours
    110. let frame = 0
    111. let mframe = 0
    112. let hframe = 0
    113. //init
    114. flipFace.style.zIndex = 1
    115. flipBack.style.zIndex = 0
    116. flip.style.transform = 'perspective(500px) rotateX(0deg)'
    117. flipFace.innerHTML = seconds
    118. bottom.innerHTML = seconds
    119. mflipFace.innerHTML = minutes
    120. mbottom.innerHTML = minutes
    121. hflipFace.innerHTML = hours
    122. hbottom.innerHTML = hours
    123. if (minutes === 59 && seconds === 59) {
    124. htimer = setInterval(() => {
    125. hframe++
    126. if (hframe > 50) {
    127. clearInterval(htimer)
    128. return
    129. }
    130. if (hframe === 1) {
    131. hTop.innerHTML = (hours + 1) === 24 ? 0 : (hours + 1)
    132. hflipBack.innerHTML = (hours + 1) === 24 ? 0 : (hours + 1)
    133. }
    134. if (hframe <= 25) {
    135. hflipFace.style.zIndex = 1
    136. hflipBack.style.zIndex = 0
    137. } else {
    138. hflipFace.style.zIndex = 0
    139. hflipBack.style.zIndex = 1
    140. }
    141. hflip.style.transform = `perspective(500px) rotateX(-${180 * hframe / 50}deg)`
    142. }, 20)
    143. }
    144. if (seconds === 59) {
    145. mtimer = setInterval(() => {
    146. mframe++
    147. if (mframe > 50) {
    148. clearInterval(mtimer)
    149. return
    150. }
    151. if (mframe === 1) {
    152. mTop.innerHTML = (minutes + 1) === 60 ? 0 : (minutes + 1)
    153. mflipBack.innerHTML = (minutes + 1) === 60 ? 0 : (minutes + 1)
    154. }
    155. if (mframe <= 25) {
    156. mflipFace.style.zIndex = 1
    157. mflipBack.style.zIndex = 0
    158. } else {
    159. mflipFace.style.zIndex = 0
    160. mflipBack.style.zIndex = 1
    161. }
    162. mflip.style.transform = `perspective(500px) rotateX(-${180 * mframe / 50}deg)`
    163. }, 20)
    164. }
    165. timer = setInterval(() => {
    166. frame++
    167. if (frame > 50) {
    168. clearInterval(timer)
    169. return
    170. }
    171. if (frame === 1) {
    172. Top.innerHTML = (seconds + 1) === 60 ? 0 : (seconds + 1)
    173. flipBack.innerHTML = (seconds + 1) === 60 ? 0 : (seconds + 1)
    174. }
    175. if (frame <= 25) {
    176. flipFace.style.zIndex = 1
    177. flipBack.style.zIndex = 0
    178. } else {
    179. flipFace.style.zIndex = 0
    180. flipBack.style.zIndex = 1
    181. }
    182. flip.style.transform = `perspective(500px) rotateX(-${180 * frame / 50}deg)`
    183. }, 20)
    184. }
    185. const cycle = () => {
    186. stimer = setInterval(() => {
    187. const date = new Date()
    188. const time = {
    189. seconds: date.getSeconds(),
    190. minutes: date.getMinutes(),
    191. hours: date.getHours()
    192. }
    193. console.log('time is', time);
    194. oneCycle(time, timer)
    195. }, 1000)
    196. }
    197. cycle()
    198. document.onvisibilitychange = function () {
    199. if (document.visibilityState === 'visible') {
    200. cycle()
    201. } else {
    202. clearInterval(timer)
    203. clearInterval(stimer)
    204. clearInterval(mtimer)
    205. clearInterval(htimer)
    206. }
    207. }
    208. </script>
    209. </body>
    210. </html>

  • 相关阅读:
    base64加密 > json字符串 > 中文转Unicode所遇问题
    Stable Diffusion部署教程,开启你的AI绘图之路
    【C++】:内存管理
    使用参数非参数和机器学习方法分析印度降雨变化,能给我国带来什么警示?
    python-(5-1)函数的形参、实参、返回值
    受了刺激,决定专升本
    数据结构——链表
    SpringBoot集成MyBatis-Plus
    Apifox和Eolink两个测试工具谁最实用?
    裸辞后吊打大厂面试官,四面拿到阿里offer后我还是选择了美团
  • 原文地址:https://blog.csdn.net/nishiweiyj/article/details/125615656