• 多值同时运动


    <!DOCTYPE html>
    <html>

        <head>
            <meta charset="UTF-8">
            <title></title>
            <style>
                #div1 {
                     100px;
                    height: 100px;
                    background: red;
                    position: absolute;
                    left: 400px;
                    top: 100px;
                }
            </style>
            <script type="text/javascript">
                window.onload = function() {

                    var oDiv1 = document.getElementById("div1");

                    oDiv1.onclick = function() {
                        
                        startMove(this, {
                             200,
                            height: 200
                        }, 10);

                    }

                    function startMove(obj, json, iSpeed) {
                        clearInterval(obj.iTimer);
                        var iCur = 0;
                        obj.iTimer = setInterval(function() {
                            
                            var iBtn=true;

                            for(var attr in json) {
                                var iTarget = json[attr];
                                if(attr == "opacity") {
                                    iCur = Math.round(css(obj, "opacity") * 100);
                                } else {
                                    iCur = parseInt(css(obj, attr));
                                }

                                if(iCur != iTarget) {
                                    iBtn=false;
                                    if(attr == "opacity") {
                                        obj.style.opacity = (iCur + iSpeed) / 100;
                                        obj.style.filter = 'alpha(opacity=' + (iCur + iSpeed) + ')';
                                    } else {
                                        obj.style[attr] = iCur + iSpeed + 'px';
                                    }
                                }

                            }
                            if(iBtn){
                                clearInterval(obj.iTimer);
                            }

                        }, 30);
                    }

                    function css(obj, attr) {
                        if(obj.currentStyle) {
                            return obj.currentStyle[attr];
                        } else {
                            return getComputedStyle(obj, false)[attr];
                        }
                    }

                }
            </script>
        </head>

        <body>
            <div id="div1"></div>
        </body>

    </html>

  • 相关阅读:
    【转】浅谈Node.js单线程模型
    进程
    网络编程:tcp、udp、socket、struct、socketserver
    Python基础练习
    面向对象:其他双下方法
    isinstance、issubclass、反射
    面向对象:__getitem__、__setitem__、__delitem__
    面向对象:classmethod、staticmethod、property
    面向对象:继承、多态、封装
    异常处理
  • 原文地址:https://www.cnblogs.com/gxywb/p/10209090.html
Copyright © 2020-2023  润新知