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

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style>
    div{width:100px;height:100px;background:red;filter:alpha(opacity=100);opacity:1;}
    </style>
    <script>
        function getStyle(obj,attr){
            return obj.currentStyle ? obj.currentStyle[attr]:getComputedStyle(obj)[attr];
        }
        function perfectStartMove(obj,json){
            clearInterval(obj.timer);
            obj.timer = setInterval(function(){
                var bStop = true;
                for(var attr in json){
                    if(attr == 'opacity'){
                        var iCur = parseInt(parseFloat(getStyle(obj,attr))*100);
                    }else{
                        var iCur = parseInt(getStyle(obj,attr));
                    }
                    var speed = (json[attr]-iCur)/8;
                    speed = speed >0 ? Math.ceil(speed):Math.floor(speed);
                    if(iCur != json[attr]){
                        bStop = false;
                    }
                    if(attr == 'opacity'){
                        obj.style.filter = 'alpha(opacity='+(iCur+speed)+');';
                        obj.style[attr] = (iCur+speed)/100;
                    }else{
                        obj.style[attr] = iCur+speed+'px';
                    }    
                }    
                if(bStop){
                    clearInterval(obj.timer);
                }
                
            },30);                
        }        
        window.onload = function(){
            var arrInput = document.getElementsByTagName('input')[0];
            var arrDiv = document.getElementsByTagName('div')[0];
            var onOff = true;
            arrInput.onclick = function(){
                if(onOff){
                    perfectStartMove(arrDiv,{300,height:300,opacity:30});
                }else{
                    perfectStartMove(arrDiv,{100,height:100,opacity:100});
                }
                onOff = !onOff;
            };
        };
        
    </script>
    </head>
    
    <body>
    <input type='button' value = '开始运动'/>
    <div></div>
    </body>
    </html>
  • 相关阅读:
    Web前端性能优化-资源合并与压缩
    关于 ES5 & ES6 数组遍历的方法
    代码优化
    解决 Vue 刷新页面后 store 数据丢失的问题
    Lombok
    Dao 与 Dto
    物理删除与逻辑删除的区别
    Java 创建对象的几种方式
    SSM + SpringBoot 常用注解
    Json Web Token (JWT)
  • 原文地址:https://www.cnblogs.com/moon-yyl/p/9001187.html
Copyright © 2011-2022 走看看