javascript - CSS animation,用 JS 修改 duration 无效
怪我咯
怪我咯 2017-04-10 14:51:47
[JavaScript讨论组]

http://jsbin.com/qafahamugu/1/edit?css,js,output


change paused running changeClass
.animated {
    -webkit-animation-duration: 1s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function:ease-in-out;
}
.animated2{
    -webkit-animation-duration: 5s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function:ease-in-out;
}

@-webkit-keyframes 'blink' {
    0% { background: rgba(255,0,0,0.5); }
    50% { background: rgba(255,0,0,0); }
    100% { background: rgba(255,0,0,0.5);}
}

.blinksth {
    width: 100px;
    height: 100px;
    -webkit-animation-name: blink;
}



var $animated = $(".animated");
$(".change").on("click",function(){
  $animated.css({
    "webkitAnimationDuration":"10s"
  });
});
$(".paused").on("click",function(){
  $animated.css({
    "webkitAnimationPlayState":"paused"
  });
});
$(".running").on("click",function(){
  $animated.css({
    "webkitAnimationPlayState":"running"
  });
});
$(".change-class").on("click",function(){
  $(".blinksth").removeClass("animated").addClass("animated2");
});

尝试了直接修改时间和切换类名的办法,有什么正确的推荐做法吗

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
PHP中文网

經測試,似乎只要在修改 -webkit-animation-duration 時移除並重新添加 -webkit-animation-name: blink 即可

黄舟

$animated.attr("style":"-webkit-animation-duration:10s!important;");这样可以用

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号