改变在IE 11中不工作的DIV的旋转速度,使用JS来更新CSS动画属性
Changing rotation speed of a DIV not working in IE 11, using JS to update CSS animation properties
我试图用简单的按钮改变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");
}
#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);
}
}
<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>
你必须删除并重新添加动画才能让它接受更改。
在改变速度后,将animation-name
更改为其他东西,然后在setTimeout
中设置animation-name
。这是一个hack,但它的技巧。
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");
}
#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);
}
}
<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>
相关文章:
- Node.js使用Series函数(模式?)实现流控制时出现意外结果
- JS-使用Ajax获取文件名
- 基本D3.js:使用数据键
- Angular Js-使用特定键打印数组
- node.js使用monk从数组中按id获取文档
- Angular.js:使用ng repeat创建2个html容器
- 使用history.js使用多个GET参数
- Node.js使用派生两个子进程,然后两个子进程如何相互交换
- Pdf.js:使用base64文件源而不是url来呈现Pdf文件
- Passport.js:使用主干网访问用户
- 图表.js 2.0 使用货币和千位分隔符格式化 Y 轴
- fabric.js:使用 Image.set() 调整图像大小是否会降低图像质量
- 整页.js使用连续滚动或循环时禁用 moveSectionUp
- 节点.js 使用可写流写入文件时出现 EBADF 错误
- 如何获得pickadate.js使用JAWS屏幕阅读器
- JS使用不同的填充
- 选择2 JS使用Ajax加载远程数据
- 从 Node.JS使用 MailGun 发送 HTML 电子邮件
- 如何让node.js使用CFML风格的#hashed#变量
- 使用主干网.js使用“d”从 ASMX 获取数据