zoukankan      html  css  js  c++  java
  • 运动函数封装(js)

    // 运动函数

    function starMove(obj,json,fnEnd){

      clearInterval(obj.timer);

      obj.timer  = setInterval(function(){

        var bStop = true;

        for(var name in json){

          var iTarget = json[name]; // 目标点

          if(name = 'opacity'){

              var cur = parseInt(parseFloat(getStyle(obj,name))*100);

          }else{

              var cur = parseInt(getStyle(obj,name));

          }

          var speed = (iTarget-cur)/8;

          speed = speed>0?Math.ceil(speed):Math.floor(speed);// 每30毫秒运动的距离,数值越小运动越慢

          if(name = 'opacity'){

              obj.style.opacity = (cur+speed)/100;

          }else{

              obj.style[name]= cur+speed+'px';

          }

          if(cur != iTarget){

            bStop = false;

          }

        }

        if(bStop){

          clearInterval(obj.timer);

          if(fnEnd){

            fnEnd();

          }

        }

      },30);

    }

    // 获取css样式

    function getStyle(obj,attr){

      if(obj.currentStyle){

        return obj.currentStyle[attr];

      }else{

        return obj.getComputedStyle(obj)[attr];

      }

    }

  • 相关阅读:
    微软开发中心的rss历史记录(22)
    asp.net dll 动态生成和调用(转)
    准备写博了
    来博客园报道啦
    web爬行器的准备工作
    跨浏览器设置标签样式
    感谢我身边的朋友们
    难过的一天:(
    12月:期待好运来
    11月 难过一整个世界都寂寞
  • 原文地址:https://www.cnblogs.com/ljblog/p/6829526.html
Copyright © 2011-2022 走看看