js 监听css3动画的执行,animation动画暂停

CSS 动画播放时,会发生以下三个事件:
animationstart -CSS 动画开始后触发
animationiteration - CSS 动画重复播放时触发
animationend - CSS 动画完成后触发

 @animationstart='animationstart'
 @animationiteration='animationiteration'
 @animationend ='animationend'

 

其他方式:
 

    var css3Am = document.querySelector("#css3Am");

    function startAni(){
        console.log("animationstart");
    }
    function  overAni(){
        console.log("animationend");
    }
    function chongfuAni(){
        console.log("animationiteration");
    }

    function overTran(){
        console.log("transitionend");
    }

    //监听transition动画结束方法
    css3Am .addEventListener("webkitTransitionEnd", overTran, false);
    css3Am .addEventListener("mozTransitionEnd", overTran, false);
    css3Am .addEventListener("MSTransitionEnd", overTran, false);
    css3Am .addEventListener("otransitionend", overTran, false);
    css3Am .addEventListener("transitionend", overTran, false);

    //监听animation动画开始方法
    css3Am .addEventListener("webkitAnimationStart", startAni, false);
    css3Am .addEventListener("mozAnimationStart", startAni, false);
    css3Am .addEventListener("MSAnimationStart", startAni, false);
    css3Am .addEventListener("oanimationstart", startAni, false);
    css3Am .addEventListener("animationstart", startAni, false);

    //监听animation动画结束方法
    css3Am .addEventListener("webkitAnimationEnd", overAni, false);
    css3Am .addEventListener("mozAnimationEnd", overAni, false);
    css3Am .addEventListener("MSAnimationEnd", overAni, false);
    css3Am .addEventListener("oanimationend", overAni, false);
    css3Am .addEventListener("animationend", overAni, false);

    //监听animation重复运动方法
    css3Am .addEventListener("webkitAnimationIteration", chongfuAni, false);
    css3Am .addEventListener("mozAnimationIteration", chongfuAni, false);
    css3Am .addEventListener("MSAnimationIteration", chongfuAni, false);
    css3Am .addEventListener("oanimationiteration", chongfuAni, false);
    css3Am .addEventListener("animationiteration", chongfuAni, false);
 
    

不同的浏览器要求使用不同的前缀:

No prefix: animationstart, animationiteration, animationend
Webkit: webkitAnimationStart, webkitAnimationIteration, webkitAnimationEnd
Mozilla: mozAnimationStart, mozAnimationIteration, mozAnimationEnd
MS:MSAnimationStart, MSAnimationIteration, MSAnimationEnd
O : oAnimationStart, oAnimationIteration, oAnimationEnd

 animation动画暂停:

animation-play-state 属性规定动画正在运行还是暂停。

animation-play-state: paused|running;
  • paused:规定动画已暂停。

  • running:规定动画正在播放。

实现放上去暂停动画: 

div {
	width: 100px;
	height: 100px;
	background-color: red;
	margin: 50px auto;
	animation: mymove 1s linear infinite;
    &:hover{
        animation-play-state:paused;//暂停动画
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值