jQuery瀑布流插件Wookmark使用實例
更新時間:2014年04月02日 10:55:28 作者:
Wookmark jQuery插件大致使用position:absolute來重構(gòu)內(nèi)容實現(xiàn)瀑布流布局,需要的朋友可以參考下
插件下載:https://github.com/GBKS/Wookmark-jQuery
官方主頁:http://www.wookmark.com/jquery-plugin
下載插件后,在網(wǎng)頁中引用插件的JS文件:
復(fù)制代碼 代碼如下:
<script src="jquery-1.8.2.min.js"></script>
<script src="jquery.wookmark.min.js"></script>
HTML代碼結(jié)構(gòu):
復(fù)制代碼 代碼如下:
<div id="main">
<ul id="tiles">
<li><img src="images/1.jpg"></li>
<li><img src="images/2.jpg"></li>
<li><img src="images/3.jpg"></li>
</ul>
</div>
<ul id="tiles">
<li><img src="images/1.jpg"></li>
<li><img src="images/2.jpg"></li>
<li><img src="images/3.jpg"></li>
</ul>
</div>
簡單用法:在html文件中添加代碼
復(fù)制代碼 代碼如下:
<script>
jQuery(function($){
$('#tiles li').wookmark();
});
</script>
jQuery(function($){
$('#tiles li').wookmark();
});
</script>
復(fù)雜一點的用法:
復(fù)制代碼 代碼如下:
<script>
jQuery(function($){
$('#tiles li').wookmark({ //這里是要實現(xiàn)瀑布流布局的對象
autoResize: true, //設(shè)置成true表示當(dāng)window窗口大小改變的時候,重新布局
container: $('#container'), //這個是容器名稱 這個容器要必須包含一個css屬性"position:relative" 否則你就會看到全部擠在頁面的左上角了
offset: 12, //2個相鄰元素之間的間距
itemWidth: 222, //指定對象的寬度
resizeDelay: 50 //這是延時效果 默認(rèn)是50
});
});
</script>
jQuery(function($){
$('#tiles li').wookmark({ //這里是要實現(xiàn)瀑布流布局的對象
autoResize: true, //設(shè)置成true表示當(dāng)window窗口大小改變的時候,重新布局
container: $('#container'), //這個是容器名稱 這個容器要必須包含一個css屬性"position:relative" 否則你就會看到全部擠在頁面的左上角了
offset: 12, //2個相鄰元素之間的間距
itemWidth: 222, //指定對象的寬度
resizeDelay: 50 //這是延時效果 默認(rèn)是50
});
});
</script>
wookmark同樣也可以配合ajax來實現(xiàn)動態(tài)加載數(shù)據(jù),不過新增之后需要重新執(zhí)行一次。
復(fù)制代碼 代碼如下:
var handler = $('#tiles li');
handler.wookmark(options);
handler.wookmark(options);
如果你在前面已經(jīng)綁定了事件,在重新執(zhí)行之前,先清除一下。
復(fù)制代碼 代碼如下:
handler.wookmarkClear();
看到比較多人在問滾動加載是怎么用的,弄個實例補充說明下:
復(fù)制代碼 代碼如下:
var handler = null;
//定義基本屬性.
var options = {
autoResize: true,
container: $('#main'),
offset: 2,
itemWidth: 210
};
//定義滾動函數(shù)
function onScroll(event) {
//是否到底部(這里是判斷離底部還有100px開始載入數(shù)據(jù)).
var closeToBottom = ($(window).scrollTop() + $(window).height() > $(document).height() - 100);
if(closeToBottom) {
//這里就是AJAX載入的數(shù)據(jù)
$.ajax({url:"data.html", dataType:"html", success:function(html){
//把新數(shù)據(jù)追加到對象中
$('#waterfall').append(html);
//清除原來的定位
if(handler) handler.wookmarkClear();
//創(chuàng)建新的wookmark對象
handler = $('#waterfall li');
handler.wookmark(options);
}
});
}
};
$(document).ready(new function() {
//綁定scroll事件.
$(document).bind('scroll', onScroll);
//第一次布局.
handler = $('#waterfall li');
handler.wookmark(options);
});
//定義基本屬性.
var options = {
autoResize: true,
container: $('#main'),
offset: 2,
itemWidth: 210
};
//定義滾動函數(shù)
function onScroll(event) {
//是否到底部(這里是判斷離底部還有100px開始載入數(shù)據(jù)).
var closeToBottom = ($(window).scrollTop() + $(window).height() > $(document).height() - 100);
if(closeToBottom) {
//這里就是AJAX載入的數(shù)據(jù)
$.ajax({url:"data.html", dataType:"html", success:function(html){
//把新數(shù)據(jù)追加到對象中
$('#waterfall').append(html);
//清除原來的定位
if(handler) handler.wookmarkClear();
//創(chuàng)建新的wookmark對象
handler = $('#waterfall li');
handler.wookmark(options);
}
});
}
};
$(document).ready(new function() {
//綁定scroll事件.
$(document).bind('scroll', onScroll);
//第一次布局.
handler = $('#waterfall li');
handler.wookmark(options);
});
相關(guān)文章
解決qrcode.js生成二維碼時必須定義一個空div的問題
這篇文章主要介紹了解決qrcode.js生成二維碼時必須定義一個空div的問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07Jquery判斷radio、selelct、checkbox是否選中及獲取選中值方法總結(jié)
這篇文章主要介紹了Jquery判斷radio、selelct、checkbox是否選中及獲取選中值方法總結(jié),本文總結(jié)的比較簡潔直白,看到的朋友按需索取,需要的朋友可以參考下2015-04-04jQuery中filter()和find()的區(qū)別深入了解
一直不是很清楚filter()方法和find()方法的區(qū)別,看jQuery Cookbook一書后,終于算是搞清楚了,下面將新的與大家分享下2013-09-09jQuery UI插件自定義confirm確認(rèn)框的方法
這篇文章主要介紹了jQuery UI插件自定義confirm確認(rèn)框的方法,實例分析了jQuery的UI插件使用技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03Jquery Uploadify上傳帶進(jìn)度條的簡單實例
本篇文章主要是對Jquery Uploadify上傳帶進(jìn)度條的簡單實例進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02