我正在尝试使用Javascript来更改div的移动量,具体取决于一天中的时间。
下面是我正在使用的代码:
<style>
.whiterose-w{
animation-duration: 0.05s;
animation-iteration-count: infinite;
position:absolute;
}
/* BETWEEN MIDNIGHT AND MIDDAY */
.whiterose07 {
animation-name: shake2;
}
@keyframes shake2 {
0% { transform: translate(0px); visibility: hidden; }
1% { visibility: visible;}
50% { transform: translate(0.7px);}
100% { transform: translate(0px); }
}
/* BETWEEN MIDDAY AND MIDNIGHT */
.whiterose56 {
animation-name: shake5;
}
@keyframes shake5 {
0% { transform: translate(0px); visibility: hidden; }
1% { visibility: visible;}
50% { transform: translate(5.6px);}
100% { transform: translate(0px); }
}
</style>
<script>
// WHITEROSE SPEEDING UP TOWARDS MIDNIGHT !
var currentTime = new Date().getHours();
if (0 <= currentTime && currentTime < 12) {
document.getElementsByClassName('whiterose-w').classList.add("whiterose07");
}
else if (12 <= currentTime && currentTime < 24) {
document.getElementsByClassName('whiterose-w').classList.add("whiterose56");
}
</script>
因此,在午夜和午夜之间,div应该移动5.6像素,而在午夜和午夜之间应该移动0.7px ..但是我在哪里错了?