banner
banner
banner
NEWS LETTER

案例-电子表指针转动Date

Scroll down

核心

  • 读秒:
    1
    2
    3
    4
    let now = new Date()
    let seconds = now.getSeconds()
    let minutes = now.getMinutes()
    let hours = now.getHours()
  • 计算指针旋转的度数
    1
    2
    3
    let secondsDeg = ((seconds /60) * 360) + 90 // 这是秒针
    let minutesDeg = ((minutes / 60) * 360) + (seconds / 3600) + 90 // 这是分针
    let hoursDeg = ((hours / 12) * 360) + (seconds/43200)*360+(mins/720)*360 + 90 // 这是时针
  • 设置指针角度
    1
    2
    3
    dom.style.transform = `rotate(${secondsDeg}deg)` // 秒针的dom旋转的角度
    dom.style.transform = `rotate(${minutesDeg}deg)` // 分针的dom旋转的角度
    dom.style.transform = `rotate(${hoursDeg}deg)` // 时针的dom旋转的角度
其他文章
cover
案例-对齐文本
  • 24/10/30
  • 15:29
  • CSS&HTML
cover
Html-html5和CSS3新特性
  • 24/10/30
  • 15:29
  • CSS&HTML
目录导航 置顶
  1. 1. 核心
请输入关键词进行搜索