|
@@ -43,12 +43,35 @@
|
|
|
oImg.style.width = this.width + 'px'
|
|
|
oImg.style.left = this.xLeft + 'px'
|
|
|
oImg.style.top = this.xTop + 'px'
|
|
|
+ this.img = oImg
|
|
|
document.body.appendChild(oImg)
|
|
|
}
|
|
|
+ //下落的方法
|
|
|
+ leaf.prototype.fall = function(){
|
|
|
+ setTimeout(function(){
|
|
|
+ this.timer = setInterval(function(){
|
|
|
+ console.log(this) //window .bind(this) this->leaf
|
|
|
+ if(this.img.offsetTop < screenHeight - this.img.offsetHeight){
|
|
|
+ this.img.style.top = this.img.offsetTop + 10 + 'px'
|
|
|
+ } else{
|
|
|
+ clearInterval(this.timer)
|
|
|
+ }
|
|
|
+ }.bind(this),20)
|
|
|
+ // console.log(this) // window .bind(this) this-> leaf
|
|
|
+ }.bind(this),Math.random()*2000)
|
|
|
+ // console.log(this) // leaf
|
|
|
+ }
|
|
|
+ var leafArr = [];
|
|
|
for(var i=0;i<20;i++){
|
|
|
//创建实例化对象
|
|
|
var leaf1 = new leaf()
|
|
|
leaf1.init()
|
|
|
+ leafArr.push(leaf1)
|
|
|
+ }
|
|
|
+ document.onclick = function(){
|
|
|
+ for(var i=0;i<leafArr.length;i++){
|
|
|
+ leafArr[i].fall()
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
</body>
|