課程
/前端開發(fā)
/JavaScript
/瀑布流布局
我json數(shù)據(jù) 寫了24個(gè)圖片, 為什么滑動(dòng)起來那么卡?
是因?yàn)槟男┓矫鏇]有進(jìn)行優(yōu)化嗎? 這樣的頁面用戶體驗(yàn)很糟糕阿 。
2016-05-27
源自:瀑布流布局 3-2
正在回答
不會(huì)呀,我試了跟jquery代碼的引用有關(guān),有的版本比較流暢,有的就比較卡
老師的這個(gè)函數(shù)是每次一觸發(fā)就把json里的數(shù)據(jù)全加載了??梢远x一個(gè)數(shù)來逐漸加載就不用遍歷循環(huán)了
$(window).on('load',function(){?waterfall();var ind = 0;var al = 0;?var dataInt = {"data":[{"src":"image/P_01.jpg"},{"src":"image/P_02.jpg"},{"src":"image/P_03.jpg"},{"src":"image/P_04.jpg"},{"src":"image/P_05.jpg"},{"src":"image/P_06.jpg"}]};?$(window).on('scroll',function(){????if(checkScrollSlide()){???if(ind==dataInt.data.length){????if(al==0){????alert("圖片已加載完畢!");????al=1;}????}else{???var oBox = $("<div>").addClass("box").appendTo($('#main'));???var oPic = $('<div>').addClass("pic").appendTo(oBox);???var oImg = $('<img>').attr('src',dataInt.data[ind].src).appendTo(oPic);???waterfall();???ind++;???if(ind==6){ind=0};???console.log(ind);}???}??});?})
? 那應(yīng)該如何修改源碼?
$(document).ready(function()?{ ????$("#container").on('mouseenter?mouseleave',?'div.photo',?function(event)?{ ????????if?(event.type?==?'mouseenter')?{ ????????????$(this).find('div.details').fadeTo('fast',?0.5) ????????}?else?{ ????????????$(this).find('div.details').fadeOut('fast') ????????} ????}); ????$('#more-photos').click(function()?{ ????????$(this).trigger('nextPage',[true]); ????????return?false; ????}) ????function?checkscrollslide(){ ????????var?$height=$(window).scrollTop()+$(window).height(); ????????if?($('#container').height()<=$height)?{ ????????????$(document).trigger('nextPage'); ????????} ????} ????$(window).scroll(checkscrollslide).trigger('scroll') ????var?pagenum?=?1; ????$(document).on('nextPage',?function(event,scrolltovisible)?{ ????????var?$href?=?$('#more-photos').attr('href'); ????????$.get($href,?function(data)?{ ????????????var?$data=$(data).appendTo('#gallery'); ????????????if?(scrolltovisible)?{ ????????????????var?newtop=$data.offset().top; ????????????????$(window).scrollTop(newtop) ????????????} ????????????checkscrollslide() ????????},?'html') ????????if?(pagenum?<?20)?{ ????????????pagenum++; ????????????$('#more-photos').attr('href',?'pages/'?+?pagenum?+?'.html'); ????????}?else?{ ????????????$('#more-photos').remove(); ????????????$(document).off('nextPage'); ????????} ????}) });
因?yàn)槊看渭虞d新的,前面的節(jié)點(diǎn)還會(huì)被重新遍歷一邊。應(yīng)該從當(dāng)前新創(chuàng)建的節(jié)點(diǎn)開始往后遍歷。
舉報(bào)
瀑布流布局是網(wǎng)站比較流行的一種布局方式,教你實(shí)現(xiàn)三大方式
1 回答滑動(dòng)滾動(dòng)條后,頁面內(nèi)容增加了,但是為什么滾動(dòng)條的位置一直是置頂?shù)膕crollTop一直為0呢?求大神們幫忙看下~
1 回答為什么我一刷新圖片就堆疊到一起了
2 回答浮動(dòng)的元素有嵌套啊,為什么
2 回答哪位大神幫忙看下為什么圖片出不來,滾動(dòng)加載不了奇怪??
1 回答為什么我的圖片沒有加載出來
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-07-14
不會(huì)呀,我試了跟jquery代碼的引用有關(guān),有的版本比較流暢,有的就比較卡
2016-06-03
老師的這個(gè)函數(shù)是每次一觸發(fā)就把json里的數(shù)據(jù)全加載了??梢远x一個(gè)數(shù)來逐漸加載就不用遍歷循環(huán)了
$(window).on('load',function(){
?waterfall();var ind = 0;var al = 0;
?var dataInt = {"data":[{"src":"image/P_01.jpg"},{"src":"image/P_02.jpg"},{"src":"image/P_03.jpg"},{"src":"image/P_04.jpg"},{"src":"image/P_05.jpg"},{"src":"image/P_06.jpg"}]};
?$(window).on('scroll',function(){
??
??if(checkScrollSlide()){
???if(ind==dataInt.data.length){
????if(al==0){
????alert("圖片已加載完畢!");
????al=1;}
????}else{
???var oBox = $("<div>").addClass("box").appendTo($('#main'));
???var oPic = $('<div>').addClass("pic").appendTo(oBox);
???var oImg = $('<img>').attr('src',dataInt.data[ind].src).appendTo(oPic);
???waterfall();
???ind++;
???if(ind==6){ind=0};
???console.log(ind);}
???}
??});
?})
2016-05-30
? 那應(yīng)該如何修改源碼?
2016-05-28
因?yàn)槊看渭虞d新的,前面的節(jié)點(diǎn)還會(huì)被重新遍歷一邊。應(yīng)該從當(dāng)前新創(chuàng)建的節(jié)點(diǎn)開始往后遍歷。