zoukankan      html  css  js  c++  java
  • css3 @keyframe 抖动/变色动画

    一.纯css实现

    .shake{    //抖动的元素
        200px;
        height: 100px;
        margin: 50px auto;
        background: #f00;
        position: relative;
    }


    /**step 2**/
    @-webkit-keyframes shake{
        0%{
            -webkit-transform:translateX(10px) rotate(10deg);
        }
        20%{
            -webkit-transform:translateX(-7px) rotate(-7deg);
        }
        40%{
             -webkit-transform:translateX(5px) rotate(6deg);
        }
        60%{
            -webkit-transform:translateX(-3px) rotate(-3deg);
        }
        80%{
            -webkit-transform:translateX(6px) rotate(5deg);
        }
       100%{
           -webkit-transform:translateX(-10px) rotate(-10deg);
        }
    }


    /**step 3**/
    .shake:hover{
        -webkit-animation-name: shake;
        -webkit-animation-duration: 0.25s;
        -webkit-animation-timing-function: linear;
        -webkit-animation-iteration-count: 1;
    }

     

    二.js实现变色动画

    html:

    <div id='a' style="200px; height:200px; margin:0 auto;"></div>

    css:

    div.a {
        animation: myfirst 1s;
        -webkit-animation: myfirst 1s;
    }

    <style id="dynamic">
    </style>

    js:

    var colors = ['red','yellow','blue','green']


    window.setTimeout(function (){   //每隔一秒,取数组中的颜色值,作为div.a的背景动画颜色,再消除颜色动画(既消除背景色)
        var color = colors.shift();
        console.log(color);
        if (!color) return


        var style = document.getElementById("dynamic");   //给style页内标签加入keyframes动画


        style.innerHTML = '@-webkit-keyframes myfirst{50% {background: '+color+';} } '+ '@keyframes myfirst {50% {background: '+color+';}}'


        var a = document.getElementById('a')

        a.className = 'a'

        window.setTimeout(function(){
            a.className = ''
        },1000)


        window.setTimeout(arguments.callee,1500);

    },1000) 

  • 相关阅读:
    python 实例方法、静态方法、类方法的区别
    locust 参数化实现
    Airtest 基于图像识别的自动化测试工具
    python 调用 dubbo 接口
    locust+geventhttpclient 性能优化
    python性能测试工具locust
    性能测试工具 wrk
    jmeter 参数化,关联参数,断言等使用说明
    Django上传excel表格并将数据写入数据库
    小程序 wx.uploadFile 上传文件 iOS 失败 400 错误排查
  • 原文地址:https://www.cnblogs.com/jlliu/p/5319202.html
Copyright © 2011-2022 走看看