zoukankan      html  css  js  c++  java
  • css3在动画完成后执行事件

    第一种方法: 
    用计时器,设定一个和动画时长一样的time,过time事件去执行这个函数。 
    setTimeout(function(){ },time); 
    第二种方法: 

    当-webkit-animation动画结束时有一个webkitAnimationEnd事件,只要监听这个事件就可以了。 

    不同浏览器的AnimationEnd写法 (webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend)

    例子: 

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>webkitAnimationEnd</title>
    <style type="text/css">
    #div1{
        margin: 200px auto 0;
        width: 200px;
        height: 200px;
        color: #fff;
        background-color: #000;
        -webkit-animation: transform 3s 2 ease;
    }
    @-webkit-keyframes transform {
        0%{
            -webkit-transform: scale(1) rotate(50deg);
        }
        30%{
            -webkit-transform: scale(2) rotate(100deg);
        }
        6%{
            -webkit-transform: scale(0.5) rotate(-100deg);
        }
        100%{
            -webkit-transform: scale(1) rotate(0);
    
        }
    }
    </style>
    </head>
    <body>
    <div id="div1"></div>
    <script type="text/javascript">
        var o = document.getElementById("div1");
       
        o.addEventListener("webkitAnimationEnd", function() {
           // this.className = "";
            alert("动画结束");
        })
    </script>
    </body>
    </html>
  • 相关阅读:
    学习笔记(4)---JQuery
    学习笔记---ES6
    angular.js的学习笔记(1)
    vue.js学习笔记(1)
    HTML5“爱心鱼”游戏总结
    学习笔记(3)---综合
    学习笔记(2)---CSS中的易混淆点
    学习笔记(1)----水平垂直居中的方法
    javascript:void(0)是什么意思
    private Int32? m_shopid;
  • 原文地址:https://www.cnblogs.com/supe/p/7682122.html
Copyright © 2011-2022 走看看