zoukankan      html  css  js  c++  java
  • jquery实现css3动画

      jquery animate改变元素样式时,只支持数字值的变化,比如width,height等,但是css3属性状态值很多都不是数字值,而是字符串和数字混合在一起,比如translate(), rotate()等等,如果要用animate使其支持css3变化,需要用到一个step参数,下面附上小demo:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="js/jquery-1.12.0.js"></script>
        <style>
            .demo{
                100px;
                height:100px;
                border:1px solid red;
            }
        </style>
    </head>
    <body>
    <button>sss</button>
        <div class="demo"></div>
    
        <script>
            var $elem,applyEffect;
            $elem=$(".demo");
            applyEffect=function($e,v){
                $e.css({
                    '-webkit-transform': 'translate3d(0px, ' +String(v)+ 'px, 0px)'
                    , '-moz-transform': 'translate3d(0px, ' +String(v)+ 'px, 0px)'
                    , 'transform': 'translate3d(0px, ' +String(v)+ 'px, 0px)'
                });
            };
            applyEffect($elem, 100);
            $("button").click(function(){
                $(".demo").animate({
                    foo:100
                },{
                    step:function(now,fx){
                        //console.log(now); //当前正在改变的属性的实时值
                       //console.log(fx); //jquery默认动画队列的名字
                        //console.log(fx.elem); //执行动画的元素
                        //console.log(fx.prop);  //执行动画的属性    aa
    //                    console.log(fx.now);  //正在改变属性的当前值
    //                    console.log(fx.end);  //动画结束之   360
                        //console.log(fx.unit);  //改变的属性的单位  px
                        //$(".demo").css({"transform":"rotate("+now+"deg)"});
                        applyEffect($elem, 100-now);
                    },
                    duration:1000
                });
            });
        </script>
    </body>
    </html>
    

      现在animate第一个参数里,插入一个字段,给到设定好的目标值,然后在step里用css来通过前面给的字段,来动态模拟动画,通过这样间接的方式实现了animate对css3动画的支持.

  • 相关阅读:
    ABAP 程序中的类 沧海
    ABAP类的方法(转载) 沧海
    More than 100 ABAP Interview Faq's(2) 沧海
    SAP and ABAP Memory总结 沧海
    ABAP Frequently Asked Question 沧海
    ABAP System Reports(Additional functions) 沧海
    ABAP Questions Commonly Asked 1 沧海
    ABAP Tips and Tricks 沧海
    ABAP System Fields 沧海
    ABAP 面试问题及答案(一):数据库更新及更改 SAP Standard (转) 沧海
  • 原文地址:https://www.cnblogs.com/vvic/p/5896141.html
Copyright © 2011-2022 走看看