K. *_*ven 3 html javascript css internet-explorer
我正在尝试使用简单的按钮更改 DIV 的旋转速度。它适用于 Chrome,但不适用于 IE。这是IE的限制吗?
var speed = 3;
document.getElementById("speedText").innerHTML = speed + "s";
function changeSpeed(change) {
speed = speed + change;
document.getElementById("speedText").innerHTML = speed + "s";
document.getElementById("rotationDiv").style.animationDuration = speed + "s";
$("#rotationDiv").load(location.href + " #rotationDiv");
}Run Code Online (Sandbox Code Playgroud)
#rotationDiv {
width: 200px;
height: 200px;
background-color: blue;
animation-name: spin;
animation-duration: 3s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="rotationDiv"></div>
<p id="speedText"></p>
<button id="button1" onclick="changeSpeed(-1)">Speed Up</button>
<button id="button2" onclick="changeSpeed(1)">Slow Down</button>Run Code Online (Sandbox Code Playgroud)
You have to remove and re-add the animation to get it to pick up the changes.
After changing the speed, change the animation-name to a something else, then in a setTimeout, set animation-name back. It's a bit of a hack, but it does the trick.
var speed = 3;
document.getElementById("speedText").innerHTML = speed + "s";
function changeSpeed(change) {
speed = speed + change;
document.getElementById("speedText").innerHTML = speed + "s";
document.getElementById("rotationDiv").style.animationDuration = speed + "s";
document.getElementById("rotationDiv").style.animationName = "x";
setTimeout(function(){
document.getElementById("rotationDiv").style.animationName = "";
},0);
$("#rotationDiv").load(location.href + " #rotationDiv");
}Run Code Online (Sandbox Code Playgroud)
#rotationDiv {
width: 50px;
height: 50px;
margin-left: 10px;
background-color: blue;
animation-name: spin;
animation-duration: 3s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="button1" onclick="changeSpeed(-1)">Speed Up</button>
<button id="button2" onclick="changeSpeed(1)">Slow Down</button>
<p id="speedText"></p>
<div id="rotationDiv"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1192 次 |
| 最近记录: |