元素.动画,在动画完成后应用样式更改
element.animate, applying style changes after the animation is finished
我正在运行一个简单的原生元素。
element.animate([{
transform: "translate(0px, 0)"
}, {
transform: "translate(200px, 0)"
}], {
duration: 1000,
iterations: 1,
delay: 0,
easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
direction: 'normal',
fill: 'both'
});
小提琴:http://jsfiddle.net/tox47k28/
问题是,动画结束后,我不能设置任何转换样式到该元素。转换的适当性似乎冻结了。
要"解冻"该属性的唯一方法是对该动画调用.cancel(),但随后,元素会恢复到初始状态。
UPDATE 29 OCT 2014
演示:http://jsfiddle.net/f27hpnjL/1/
你不能再用"fill: both"来"unfreeze"动画了。如果你想操作样式之后,你需要"fill: backwards":
element.animate([{
transform: "translate(0px, 0)"
}, {
transform: "translate(200px, 0)"
}], {
duration: 1000,
iterations: 1,
delay: 0,
easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
direction: 'normal',
fill: 'backwards' // Use this inorder to manipulate the style attribute after animation end
}).onfinish = function(e){
// I wish I had a refference to my keyframes here!!!
// Reset the last keyFrame
element.style.webkitTransform = "translate(200px, 0)";
// Cancel the animation
this.cancel();
}
你能用这个吗?
var animation = element.animate([{
transform: "translate(0px, 0)"
}, {
transform: "translate(200px, 0)"
}], {
duration: 1000,
iterations: 1,
delay: 0,
easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
direction: 'normal',
fill: 'both'
});
animation.onfinish = function () {
animation.cancel();
element.style.transform = "translate(400px, 0)"
}
http://jsfiddle.net/tox47k28/2/相关文章:
- 使用Ember的Web应用程序架构.动画逻辑应该放在哪里
- 猫头鹰旋转木马动画未在Chrome中应用
- Css动画-setTimeout没有't应用打断动画的更改
- 动画功能不应用于每个元素
- 应用jQuery动画时出现意外的抖动效果
- 如何将jquery动画应用于单个项目
- 如何将 jquery 动画应用于我的弹出窗口
- iPhone应用程序或移动野生动物园的动画PNG文件的替代方案,目标是模拟短视频剪辑的即时播放
- 始终运行的 Web 应用程序上的动画滞后和性能问题
- 在不同的对象上应用相同的 id 并分别对它们进行动画处理 (jQuery)
- 对应用了自由变换的图像进行动画处理
- 无法使用 JS 应用核心动画页面过渡
- 未应用元素上的动画
- 在 yeoman 中使用动画模块编译 AngularJS 应用程序会给出未知的提供程序错误
- 对画布上的移动形状或动画形状应用持续时间
- 如何在用JavaScript或NodeJs编写的控制台应用程序中制作加载动画
- 当内容在视口中时应用css动画(以及页面堆积.js)
- Winjs Windows 应用程序中的 D3 动画
- jQuery UI-在没有鼠标干预的情况下将Resizable()动画应用于块元素
- AngularJS:如何有条件地应用视图动画