亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

滑動起來為什么那么卡?

我json數據 寫了24個圖片, 為什么滑動起來那么卡?

是因為哪些方面沒有進行優化嗎? 這樣的頁面用戶體驗很糟糕阿 。

正在回答

4 回答

不會呀,我試了跟jquery代碼的引用有關,有的版本比較流暢,有的就比較卡

0 回復 有任何疑惑可以回復我~

老師的這個函數是每次一觸發就把json里的數據全加載了??梢远x一個數來逐漸加載就不用遍歷循環了

$(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);}
???}
??});
?})

0 回復 有任何疑惑可以回復我~

? 那應該如何修改源碼?

$(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');
????????}
????})

});


0 回復 有任何疑惑可以回復我~

因為每次加載新的,前面的節點還會被重新遍歷一邊。應該從當前新創建的節點開始往后遍歷。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

滑動起來為什么那么卡?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號