$(function () { var boxs='' for(var i=1;i<=70;i++){ boxs+='<div class=\'boxs\'><h2>哈哈哈哈</h2><img src=img/'+i+'.jpg><p>为什么这么的难啊难</p></div>'; } $('.main').html(boxs); var obj= { init: function () { this.lie = Math.floor($('.main').width() / $('.boxs').outerWidth()); this.space = ($('.main').width() - this.lie * $('.boxs').outerWidth()) / (this.lie + 1); this.gao = 15; this.arrXY=[]; this.two(); }, two: function(){ for(var i=0;i<this.lie;i++){ var pos={ left:(i*$('.boxs').eq(i).outerWidth()+(this.space*(i+1))), top: $('.boxs').eq(i).outerHeight()+this.gao*2 } $('.boxs').eq(i).animate({ top:this.gao, left:(i*$('.boxs').eq(i).outerWidth()+(this.space*(i+1))) },1000); this.arrXY.push(pos); } this.three(); }, three:function () { for(var i=this.lie;i<=70;i++){ var index=this.getMinTop(); $('.boxs').eq(i).animate({ left:this.arrXY[index].left, top:this.arrXY[index].top },1000) this.arrXY[index].top+=$('.boxs').eq(i).outerHeight()+this.gao; } }, getMinTop:function(){ var mixHeight=this.arrXY[0].top; var index=0; for(var i=0;i<this.arrXY.length;i++){ if(mixHeight>this.arrXY[i].top){ mixHeight=this.arrXY[i].top; index=i; } } return index; } } obj.init() $(window).resize(function(){ obj.init(); }) })
|