zoukankan      html  css  js  c++  java
  • js实现jquery函数animate动画效果

    <script>

    function animate(obj, json, interval, sp, fn) {
    clearInterval(obj.timer);
    function getStyle(obj, arr) {
    if(obj.currentStyle){
    return obj.currentStyle[arr]; //针对ie
    } else {
    return document.defaultView.getComputedStyle(obj, null)[arr];
    }
    }


    /* function getStyle(dom, pro) {
    if (window.getComputedStyle) {
    return window.getComputedStyle(dom, null)[pro]
    } else {
    if (dom.currentStyle) {
    return dom.currentStyle[pro]
    } else {
    return dom.style[pro]
    }
    }
    }*/



    obj.timer = setInterval(function(){

    var flag = true;

    for(var arr in json) {
    var icur = 0;
    if(arr == "opacity") {
    icur = Math.round(parseFloat(getStyle(obj, arr))*100);
    } else {
    icur = parseInt(getStyle(obj, arr));
    }
    var speed = (json[arr] - icur) * sp;
    speed = speed > 0 ? Math.ceil(speed): Math.floor(speed);
    if(icur != json[arr]){
    flag = false;
    }
    if(arr == "opacity"){
    obj.style.filter = "alpha(opacity : '+(icur + speed)+' )";
    obj.style.opacity = (icur + speed)/100;
    }else {
    obj.style[arr] = icur + speed + "px";

    }
    //console.log(j + "," + arr +":"+ flag);
    }

    if(flag){
    clearInterval(obj.timer);
    //console.log(j + ":" + flag);
    //console.log("k = " + k);
    //console.log("j = " + j);
    //console.log("DONE");
    if(fn){ fn(); }
    }
    },interval);
    }

    </script>
    <ul id="move" style="list-style:none;font-family:'Arial';color:White">
    <li style="200;height:60;background-color:red">AAAAA</li>
    <li style="200;height:60;background-color:blue">BBBBB</li>
    <li style="200;height:60;background-color:Navy">CCCCCC</li>
    <li style="200;height:60;background-color:green">DDDDDD</li>
    <li style="200;height:60;background-color:pink">EEEEE</li>
    </ul>
    <script>
    var move = document.getElementById("move").getElementsByTagName("li");
    for(var i = 0; i < move.length; i ++){
    move[i].onmouseover = function(){
    var _this = this;
    animate(_this, { 500, height: 60},10, 0.1, function(){
    // animate(_this, { 200, height: 100},10, 0.1);
    });
    }

    move[i].onmouseout = function(){
    animate(this, { 200, height: 60},10, 0.1);
    }
    }

    </script>

  • 相关阅读:
    进程与线程
    the art of seo(chapter seven)
    the art of seo(chapter six)
    the art of seo(chapter five)
    the art of seo(chapter four)
    the art of seo(chapter three)
    the art of seo(chapter two)
    the art of seo(chapter one)
    Sentinel Cluster流程分析
    Sentinel Core流程分析
  • 原文地址:https://www.cnblogs.com/yzryc/p/6047306.html
Copyright © 2011-2022 走看看