zoukankan      html  css  js  c++  java
  • JS中的混合模式

    function Animation(list) {
        this.box = document.getElementById(list.id);
        this.size = list.size;
        this.url = list.url;
        
        this.init()            //    Animation.prototype中的init(),初始化一些值(非私有)
        this.DOMready();    //    调用Animation.prototype中的 DOMready(),每一个new Animation()都会执行这里面的语句
    }
    
    Animation.prototype = {
        //    1.init:初始化一些非私有值
        init:function(){
            this.width  = box.clientWidth;
            this.height = box.clientHeight;
        },
        
       //    2.DOMready:用来生成div的,用到定时器,循环设置
        DOMready: function(){
            var box = this.box;
            var size = this.size;
            // 下面保存了this(Animation)到self之中,因为等会要调用Animation.DOMmove(cirDiv)
            var self = this;
            
            var timer = setInterval(function(){
                var top = 0;
                var xPosition = Math.random()*(self.width - self.size);
                var cirDiv = document.createElement("div");
                cirDiv.style.cssText = "background:"+LYX_Colors_getRandomColor()+";"+"left:"+xPosition+"px;"+ "25px;height:25px;border-radius: 50%;position: absolute;";
                box.appendChild(cirDiv);
                
                //    调用Animation.DOMmove(cirDiv),给每个div设置定时器,用来调整top值
                self.DOMmove(cirDiv)        
            }, 300)
        },
        
        //    3.调整top值函数
        DOMmove: function(cirDiv) {
            var top = 0;
            var self = this;
            var cirDiv = cirDiv;
            var timer_2 = setInterval(function() {
                top++;
                cirDiv.style.top = top+"px";
                if (top > self.height - self.size) {
                    box.removeChild(cirDiv);
                    clearInterval(timer_2);
                }
            },1)
        }
    }
    
     
    
    //    新建s调用方法
    var s = new Animation({
        id: "box",
        size: "10"
    });
  • 相关阅读:
    centos下安装Anaconda
    centos下安装python2.7.9和pip以及数据科学常用的包
    mysql基础(5)-关联(mysql+pandas)
    mysql基础(4)-数据导入
    mysql基础(3)-高级查询
    mysql基础(2)-数据处理(mysql+pandas)
    mysql基础(1)-基本操作
    创建线程的三种方法
    Jar 包 及运行Jar包
    导出成可运行jar包时所遇问题的解决办法
  • 原文地址:https://www.cnblogs.com/nemoro1928/p/5383849.html
Copyright © 2011-2022 走看看