option css3,jquery - Css3 animation reset option - Stack Overflow

As @Fabrizio Calderan pointed out, you'll have to clone, remove and append a new element to restart the animation.

Just removing and adding the class won't work because we will restart an animation without telling that the animation is stopped so the listener won't be activated...

So to solve your problem you should recreate and append a new element like this (this is the jQuery way to stay simple, but you can do it with vanilla JS too) :

function reanimateWrapper(){

var $wrapper = $('#animation-bg');

var $clonedWrapper = $wrapper.clone().removeClass('animate');

$wrapper.remove();

$('body').prepend($clonedWrapper);

$('#animation-bg').addClass('animate');

}

And as a CSS tips, the animation-delay property can be specified in the generic animation property too. Like :

animation: single-animation-name animation-duration animation-direction animation-delay

See full solution with this updated fiddle : https://jsfiddle.net/75qb2sfk/3/

Note: I added jQuery to the fiddle to keep the code simple, and restructured your CSS to have a specific class for animations)

Update: after reading the CSStrick link of Fabrizio, it seems that there is a way to restart the animation by removing then adding the class if we use a timer. But as they wrote in the article, this isn't a good way to go...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值