In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge of this article "how to achieve clock effect based on HTML5+CSS3", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to achieve clock effect based on HTML5+CSS3" article.
Objective:
Using html5,css to realize pendulum effect
Knowledge points:
1) using position/left/top and calc () to center elements horizontally and vertically.
2) use the animation/transform/transform-origin attribute of CSS3 to define animation
3) using transform-origin to adjust the center of the rotation origin.
The specific code is as follows:
Li {list-style:none;} # box {width: 400px; height: 400px; position: absolute; top:calc (50%-200px); left:calc (50%-200px); border: 2px solid palegoldenrod;} # dial {width: 200px Height: 200px; position: absolute; top:calc (50%-100px); left:calc (50%-100px); border: 2px solid cyan; border-radius: 50%;} .scaleIndex {width: 4px; height: 12px; position: absolute Top: 0; left: calc (50-2px); background-color: gray; transform-origin: 2px 100px;} .angle30 {transform: rotate (30deg);} .angle60 {transform: rotate (60deg);} .angle90 {transform: rotate (90deg);} .angle120 {transform: rotate (120deg);} .angle150 {transform: rotate (150deg) } .angle180 {transform: rotate (180deg);} .angle210 {transform: rotate (210deg);} .angle240 {transform: rotate (240deg);} .angle270 {transform: rotate (270deg);} .angle300 {transform: rotate (300deg);} .angle330 {transform: rotate (330deg);} # fixPoint {width: 10px; height: 10px; position: Top:calc (50-5px); left:calc (50-5px); background-color: cadetblue; border-radius: 50%;} # hourHand {width: 6px; height: 70px; position:absolute; top: 40px; left:calc (50-3px) Background-color: darkblue; transform-origin: 50% 60px;} # minuteHand {width: 4px; height: 75px; position:absolute; top: 35px; left: calc (50%-2px); background-color: yellow; transform-origin: 50% 65px } # secondHand {width: 2px; height: 90px; position:absolute; top: 20px; left: calc (50%-1px); background-color: red; transform-origin: 50% 80px } _ window.onload = function () {var hourHand = document.getElementById ('hourHand') Var minuteHand = document.getElementById ('minuteHand'); var secondHand = document.getElementById (' secondHand'); setInterval (function () {var currentTime = new Date (); var hourValue = currentTime.getHours (); var hourAngle = hourValue / 24 * 360 + 'deg'; var minuteValue = currentTime.getMinutes () Var minuteAngle = minuteValue / 60 * 360 + 'deg'; var secondValue = currentTime.getSeconds (); var secondAngle = secondValue / 60 * 360 +' deg'; console.log (hourAngle); / / method 1: use jquery's css () to add attribute var cmdHour = 'rotate (' + hourAngle +')' $('# hourHand'). Css ({transform:'rotate ('+ hourAngle +')'}); var cmdMinute = 'rotate (' + minuteAngle +')'; $('# minuteHand'). Css ({transform:cmdMinute}); var cmdSecond = 'rotate (' + secondAngle +')'; $('# secondHand'). Css ({transform:cmdSecond}); / / method 2: use the style attribute of the DOM element to set / / hourHand.style.transform = 'rotate (' + hourAngle +')' / / minuteHand.style.transform = 'rotate (' + minuteAngle +')'; / / secondHand.style.transform = 'rotate (' + secondAngle +')';}, 1000) } the above is about the content of this article on "how to achieve clock effect based on HTML5+CSS3". I believe you all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.