`
一、效果显示
名称:JS时钟应用练习,语言: JS,
项目效果如下图
二、部分核心代码
Hml图片
Js图片
Index.Hml
<div>
<div>
<text>1</text>
<text>2</text>
<text>3</text>
<text>4</text>
<text>5</text>
<text>6</text>
<text>7</text>
<text>8</text>
<text>9</text>
<text>10</text>
<text>11</text>
<text>12</text>
<div></div>
<text id="hourHand">→</text>
<text id="minuteHand">--→</text>
<text id="secondHand">----→</text>
</div>
</div>
Index.js
export default {
data: {
hourHand: "rotate(-90deg)",
minuteHand: "rotate(-90deg)",
secondHand: "rotate(-90deg)"
},
onInit() {
const _this = this
let hour = new Date().getHours()
let minute = new Date().getMinutes()
let second = new Date().getSeconds()
hour %= 12
_this.hourHand = "rotate(" + (hour * 30 - 90) + "deg)"
_this.minuteHand = "rotate(" + (minute * 6 - 90) + "deg)"
_this.secondHand = "rotate(" + (second * 6 - 90) + "deg)"
setInterval(function () {
let hour = new Date().getHours()
let minute = new Date().getMinutes()
let second = new Date().getSeconds()
hour %= 12
_this.hourHand = "rotate(" + (hour * 30 - 90) + "deg)"
_this.minuteHand = "rotate(" + (minute * 6 - 90) + "deg)"
_this.secondHand = "rotate(" + (second * 6 - 90) + "deg)"
}, 1000);
}
}
三、完整代码地址
https://gitee.com/jltfcloudcn/jump_to/tree/master/JS%E6%97%B6%E9%92%9F
附件:
`