zoukankan      html  css  js  c++  java
  • javascript运动框架

    //运动框架
    function sportFrame(obj,json,fun){
        var timer;
        clearInterval(obj.timer);
        obj.timer=setInterval(function(){
            var Stop=true;
            for(var name in json){
                var val=0;
                //判断是不是透明度
                if(name=='opacity'){
                    val=Math.round(parseFloat(cssStyle(obj,name))*100);
                }else{
                    val=parseInt(cssStyle(obj,name));
                }
                //缓冲速度
                var speed=(json[name]-val)/10;
                speed=speed>0?Math.ceil(speed):Math.floor(speed);
                if(val!=json[name]){
                    if(name=="opacity"){
                        obj.style.filter='alpha(opacity:'+val+speed+')';//IE
                        obj.style.opacity=(val+speed)/100;
                    }else{
                        cssStyle(obj,name,val+speed+'px');
                    }
                }
            }
            //判断是否达到终点
            if(Stop){
                clearInterval(timer);        
                if(fun){
                    fun();
                }
            }    
        },30);
    }
    
    //获取属性值和设置属性值框架
    function cssStyle(obj,prop,value){
        //style只能获取写在html标签中的写在style属性中的值(style=”…”),
        //而无法获取定义在<style type="text/css">里面的属性
        //currentStle,getComputedStyle方法可以获取内联或者外部的样式
        //获取样式
        if(arguments.length==2){
            if(obj.currentStyle){
                return obj.currentStyle[prop];  //IE
            }else{
                return getComputedStyle(obj,false)[prop];  //Fire
            }
        }
        //设置样式
        else{
            if(arguments.length==3){
                obj.style[prop]=value;
            }
        }
    }
  • 相关阅读:
    Makefile文件(五)_使用变量
    Makefile文件(四)_书写命令
    Makefile文件(三)_书写规则
    Makefile文件(二)_总述
    Makefile文件(一)_介绍
    select、poll和epoll
    LintCode 子树
    LintCode 字符串查找
    LintCode 用栈实现队列
    LintCode 丑数
  • 原文地址:https://www.cnblogs.com/wgj32/p/5700368.html
Copyright © 2011-2022 走看看