關(guān)于沒有滾動(dòng)條時(shí)圖片加載
圖片太少或者尺寸較小時(shí),一個(gè)頁面加載完,沒有滾動(dòng)條,就無法觸發(fā)加載數(shù)據(jù)。
可以先執(zhí)行一次加載解決。
window.onload=function(){ waterfall('main','box'); var?dataInt={"data":[{"src":'1.jpg'},{"src":'2.jpg'},{"src":'3.jpg'},{"src":'4.jpg'},{"src":'5.jpg'},{"src":'6.jpg'},{"src":'7.jpg'},{"src":'8.jpg'},{"src":'9.jpg'},{"src":'10.jpg'},{"src":'11.jpg'},{"src":'12.jpg'},{"src":'13.jpg'},{"src":'14.jpg'},{"src":'15.jpg'},{"src":'16.jpg'},{"src":'17.jpg'}]}; addpic(); window.onscroll=function(){ if(checkScrollSlide){ addpic(); } } function?addpic(){ var?oParent=document.getElementById('main'); for(var?i=0;i<dataInt.data.length;i++){ var?oBox=document.createElement('div'); oBox.className='box'; oParent.appendChild(oBox); var?oPic=document.createElement('div'); oPic.className='pic'; oBox.appendChild(oPic); var?oImg=document.createElement('img'); oImg.src="img/"+dataInt.data[i].src; oPic.appendChild(oImg); } waterfall('main','box'); } }
但是把這個(gè)加載函數(shù),放在window.onload外面調(diào)用就不行了,求解。為何別的函數(shù)都可以放在外面調(diào)用,這個(gè)放外面就不行了。
window.onload=function(){ waterfall('main','box'); var?dataInt={"data":[{"src":'1.jpg'},{"src":'2.jpg'},{"src":'3.jpg'},{"src":'4.jpg'},{"src":'5.jpg'},{"src":'6.jpg'},{"src":'7.jpg'},{"src":'8.jpg'},{"src":'9.jpg'},{"src":'10.jpg'},{"src":'11.jpg'},{"src":'12.jpg'},{"src":'13.jpg'},{"src":'14.jpg'},{"src":'15.jpg'},{"src":'16.jpg'},{"src":'17.jpg'}]}; addpic(); window.onscroll=function(){ if(checkScrollSlide){ addpic(); } } } function?addpic(){ var?oParent=document.getElementById('main'); for(var?i=0;i<dataInt.data.length;i++){ var?oBox=document.createElement('div'); oBox.className='box'; oParent.appendChild(oBox); var?oPic=document.createElement('div'); oPic.className='pic'; oBox.appendChild(oPic); var?oImg=document.createElement('img'); oImg.src="img/"+dataInt.data[i].src; oPic.appendChild(oImg); } waterfall('main','box'); }
2016-05-25
在沒有onload完頁面之前,,addpic函數(shù)中,怎么能尋找到main,div,img這些東西,這些DOM都還沒加載進(jìn)來