-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfallspic.js
33 lines (32 loc) · 960 Bytes
/
fallspic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
fallspic 1.0
Autor: Hu Yicheng
Update: 2014-04-17
Usage: $("selector").fallspic({picWidth:250,lineShowNum:4});
*/
(function($){
$.fn.fallspic = function(options){
var opt = $.extend({picWidth:200,lineShowNum:4},options);
this.each(function(){
$(this).width(opt.picWidth*opt.lineShowNum);
var obj = $(this).children(":visible"),len = obj.length,colArr = new Array(opt.lineShowNum),minColHeight = 0,maxColHeight = 0,objHeight = 0;
$.each(colArr,function(i){
colArr[i] = 0;
});
obj.each(function(i){
minColHeight = Math.min.apply(Math,colArr);
obj.eq(i).css({"top":minColHeight});
objHeight = obj.eq(i).outerHeight(true);
for(var j = 0; j < opt.lineShowNum; j++){
if(colArr[j] == minColHeight){
colArr[j] += objHeight;
obj.eq(i).css({"left":j*opt.picWidth+"px"});
break;
}
}
});
maxColHeight = Math.max.apply(Math,colArr);
$(this).height(maxColHeight);
});
}
})(jQuery);