好的,所以我想讓這兩個div每隔三秒切換一次。我的問題是:我應該如何在JavaScript中做到這一點?我想創造一個明快的效果。請忽略我的代碼中的小錯誤,即時通訊尚未完成。使用javascript自動在兩個div之間切換
<!DOCTYPE html>
<html>
<head>
<title>STROBE</title>
<style>
#strobe {
animation-name: blinker;
animation-duration: 0.2s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: alternate;
width:100%;
height:100%;
padding:0;
margin:0;
border: 1px solid blue;
-webkit-animation-name: blinker;
-webkit-animation-duration: 0.06s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
}
@-webkit-keyframes blinker {
0% { background-color:green; }
25% { background-color:#5D96FF; }
50% { background-color:F0BE00; }
75% { background-color:#710595; }
100% { background-color:red; }
}
@keyframes blinker {
0% { background-color:green; }
25% { background-color:#5D96FF; }
50% { background-color:F0BE00; }
75% { background-color:#710595; }
100% { background-color:red; }
}
#baw {
animation-name: bw;
animation-duration: 1s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: alternate;
width:100%;
height:100%;
padding:0;
margin:0;
border: 1px solid red;
-webkit-animation-name: bw;
-webkit-animation-duration: 0.06s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
}
@-webkit-keyframes bw {
0% { background-color:black; }
100% { background-color:white; }
}
@keyframes bw {
0% { background-color:black; }
100% { background-color:white; }
}
</style>
</head>
<body style="width:100%;height:1800px;">
<div id="strobe"></div>
<div id="baw";></div>
</body>
</html>
可能會更好做使用'style.display'與無/塊如果你希望他們在同一個位置。'visibility:hidden'被隱藏,但會佔用空間 – Martijn