樓主您好
宛城網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),宛城網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為宛城成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的宛城做網(wǎng)站的公司定做!
引入infinitescroll
頁面元素
div data-am-widget="list_news" class="am-list-news am-list-news-default" style="margin:0px 10px 0px 10px;"
!--列表標題--
div class="am-list-news-bd"
ul class="am-list block" id="container"/ul
/div
/div
div class="loading" style="text-align:center;"
/div
div id="navigation"
a/a
/div
初始化
var navigationUrl = "xxxx?pageNo=1";
$("#navigation a").attr("href", navigationUrl);
$.ajax({
url: 'xxxx',
type: 'post',
dataType:'json',
success: function(items) {
var html = successCallBack(items);//渲染每一個瀑布流塊
$('#container').html(html);
},
error: function() {
alert('加載失敗');
}
});
初始化方法調(diào)用
$('#container').infinitescroll({
navSelector : "#navigation", //導航的選擇器,會被隱藏
nextSelector : "#navigation a", //包含下一頁鏈接的選擇器
itemSelector : ".block", //你將要取回的選項(內(nèi)容塊)
debug : true, //啟用調(diào)試信息
animate : true, //當有新數(shù)據(jù)加載進來的時候,頁面是否有動畫效果,默認沒有
extraScrollPx : 150, //滾動條距離底部多少像素的時候開始加載,默認150
bufferPx : 40, //載入信息的顯示時間,時間越大,載入信息顯示時間越短
errorCallback : function() {
//alert('error');
}, //當出錯的時候,比如404頁面的時候執(zhí)行的函數(shù)
localMode : true, //是否允許載入具有相同函數(shù)的頁面,默認為false
dataType : 'json',//可以是json
template: function(items) {
itemsTemp = items;
return successCallBack(items);
},
loading : {
img: '${ctx}/images/loading.gif',
msgText : "加載中...",
finishedMsg : '沒有新數(shù)據(jù)了...',
selector : '.loading' // 顯示loading信息的div
}
}, function() {
});
$(document).ready(function(){ $(".item").each(function(){ var leftVal=$(this).css("left"); if(leftVal=="0px") { $(this).attr("class","left z"); } }); }); ... ... ... ... ... 試試看,隨手寫的= =
這個加載數(shù)據(jù)是JS 控制的 ,ready函數(shù)會在頁面加載完成后自動執(zhí)行 加載數(shù)據(jù) 看看你的JS代碼 全部的JS注釋掉 或者改成 function query (){ $.doSerch("","");//自行補充,你代碼中的一部分 } 最后你的查詢按鈕調(diào)用這個function 就行了
我們可以使用 jQuery 的 Masonry 插件來實現(xiàn)這種頁面形式,下面介紹一下方法。
1,分別下載 jQuery 與 Masonry ,然后把他們都加載到頁面中使用。
加載代碼:
script src=""/scriptscript src=""/script
解釋:很簡單,就是把下載之后的腳本文件嵌入到你想使用瀑布流形式的頁面中,注意文件的名稱與路徑,根據(jù)你自己的實際情況修改。
2,頁面代碼
div id="masonry" class="container-fluid" div class="box"img src=""/div div class="box"img src=""/div div class="box"img src=""/div div class="box"img src=""/div div class="box"img src=""/div .../div
解釋:把每個小內(nèi)容塊放在一個擁有相關(guān)類的容器里,然后把所有的內(nèi)容塊放在一個大的容器里,這里我們把內(nèi)容塊圖片放在一個擁有 .box 類的 div 標簽里,然后把他們又使用帶有 #masonry ID 的 div 里面,一會兒我們會用 #masonry ID 和 .box 類來觸發(fā)使用瀑布流。
3,樣式代碼
.container-fluid { padding: 20px; }.box { margin-bottom: 20px; float: left; width: 220px; } .box img { max-width: 100%}
解釋:針對第二步的頁面代碼,我們需要添加一點樣式,.box 類我們添加了浮動屬性,還設(shè)置了他的寬度。
4,在頁面中啟用瀑布流形式的腳本代碼
$(function() { var $container = $('#masonry'); $container.imagesLoaded(function() { $container.masonry({ itemSelector: '.box', gutter: 20, isAnimated: true, }); });});br
解釋:這里我們首先定位想使用瀑布流的大容器是什么,這里就是帶有 #masonry ID 的 div 標簽,在 var $container = $('#masonry'); 這行代碼中定義。然后我們還要說明瀑布流里的每個內(nèi)容塊容器上共同的類是什么,這里就是帶有 .box 類的 div 標簽,在itemSelector : '.box', 這行代碼中定義。
gutter: 20, 這行代碼定義了內(nèi)容塊之間的距離是 20 像素,isAnimated: true, 這行代碼可以打開動畫選項,也就是當改變窗口寬度的時候,每行顯示的內(nèi)容塊的數(shù)量會有變化,這個變化會使用一種動畫效果。
我的一個笨方法:
$(function() { var $objbox = $("#masonry"); var gutter = 25; var centerFunc, $top0; $objbox.imagesLoaded(function() { $objbox.masonry({ itemSelector: "#masonry .box", gutter: gutter, isAnimated: true }); centerFunc = function() { $top0 = $objbox.children("[style*='top: 0']"); $objbox.css("left", ($objbox.width() - ($top0.width() * $top0.length + gutter * ($top0.length - 1))) / 2).parent().css("overflow", "hidden"); }; centerFunc(); }); var tur = true; $(window).resize(function() { if (tur) { setTimeout(function() { tur = true; centerFunc(); }, 1000); tur = false; } });});
jquery masonry 瀑布流居中
itemSelector class選擇器,默認'.item',這個表示每個塊的選擇器
columnWidth 一列的寬度
isAnimated 使用jquery的布局變化,默認true
animationOptions animate屬性漸變效果(Object { queue: false, duration: 500 })
gutterWidth 列的間隙 Integer
isFitWidth 自適應瀏覽器寬度Boolean
isResizableL 是否可調(diào)整大小 Boolean
isRTL 使用從右到左的布局 Boolean
你是說圖片重疊把。瀑布流是需要在圖片都加載完后,才出去初始化瀑布流插件。如果你直接在dom加載完去初始化,圖片沒加載完,會導致重疊。
當前標題:jquery瀑布流,jquery瀑布流插件
本文URL:http://chinadenli.net/article24/dsdcpce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、ChatGPT、網(wǎng)站設(shè)計、軟件開發(fā)、手機網(wǎng)站建設(shè)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)