瀑布流布局
2014-04-15 20:47
232 查看
组件:
调用方式:
$(".list").layout({
width:200,//单列的宽度
lineNum:3,//一列展示几排
url:''
})
$.fn.layout = function(params){ return this.each(function(){ var options = $.extend({width:100,lineNum:3,defaultData:'had'},params), $self = $(this); var layout = { width : options.width, height : [], end : false, init : function(){ this.setHeightArray(); this.bind(); if(options.defaultData == 'had'){ this.append($self.children(),true); }else{ this.getData(); } }, getData : function(){ var me = this; if($self.next('.loading').length <= 0){ $self.after('<div class="data-loading loading"><span>加载更多数据</span></div>') } $self.next('.loading').show() $.getJSON(options.url,{},function(d){ me.append(d.list) },'json') }, append : function(data,bool){ if(data.length > 0){ $self.next('.loading').hide() for(var i = 0 ,len = data.length; i < len; i++){ var d = $(data[i]), height = 0; if(!bool){ $self.append(d); } height = d.outerHeight(true); var pos = this.getPos(height) d.css({top:pos.top,left:pos.left}).fadeIn(); $self.height(pos.height); } }else{ $self.next('.loading').html('没有更多数据').show() this.end = true; } }, setHeightArray : function(){ for(var i = 0; i < options.lineNum; i ++){ this.height.push(0) } }, getPos : function(height){ var min = Math.min.apply(null, this.height), index = $.inArray(min,this.height), left = index * this.width, top = min; this.height[index] = this.height[index] + height; return {left : left , top : top, height : Math.max.apply(null, this.height)} }, bind : function(){ var body = document.body, doc = document.documentElement, me = this; $(window).on('scroll',function(){ if(me.end) return; var scrollHeight = Math.max(body.scrollHeight,doc.scrollHeight), scrollTop = Math.max(body.scrollTop,doc.scrollTop); clientHeight = doc.clientHeight; if(scrollHeight < scrollTop + clientHeight + 300){ me.getData() } }) } } layout.init() }) }
调用方式:
$(".list").layout({
width:200,//单列的宽度
lineNum:3,//一列展示几排
url:''
})
相关文章推荐
- 正则表达式
- 本章主要介绍C语言程序的结构和书写规则,以及Turbo C V2.0的基本操作
- hdu 1285 确定比赛名次 解题报告
- Cracking the coding interview--Q19.6
- ZOJ-3778
- Conversion to Dalvik format failed with error 1
- POJ1008
- 委托异步调用时BeginInvoke的陷阱处理
- 一个程序调用另一个程序 linux平台
- 排序算法总结篇
- Rsync 服务器启动错误:failed to create pid file /var/run/rsyncd.pid: File exists
- 二叉树的确定
- 【Linux】目录配置
- 欧拉道路 和 欧拉回路
- 在算法设计中使用策略模式
- NYOJ238小明的调查作业
- 开放平台
- 链表排序(冒泡、选择、插入、快排、归并、希尔、堆排序)【转载】
- PCL 打印语言 介绍
- IIS5 IIS6 IIS7区别