大神幫我看看:我的圖片地址是。。/img 類型怎么寫(xiě)???寫(xiě)了不正確? 報(bào)錯(cuò):GET http://127.0.0.1:8020/text/html/img/1H.ico [HTTP/1.1 404 Not Found 1ms]
報(bào)錯(cuò):GET
http://127.0.0.1:8020/text/html/img/1H.ico ??[HTTP/1.1 404 Not Found 1ms]
window.onload = function(){
?? ??? ??? ?//傳入要操作盒子的父元素和 要操作的盒子
?? ??? ??? ?waterfall("main","box");
?? ??? ??? ?var da = {"data":[{"src":"1H.ico"},{"scr":"DD.ico"},{"src":"GM.ico"}]};
?? ??? ??? ?window.onscroll = function(){
?? ??? ??? ??? ?if(checkScrollSlide){
?? ??? ??? ??? ??? ?//數(shù)據(jù)塊放尾部
?? ??? ??? ??? ??? ?var main = document.getElementById("main");
?? ??? ??? ??? ??? ?for(var i=0; i<da.data.length; i++){
?? ??? ??? ??? ??? ??? ?var box = document.createElement("div");
?? ??? ??? ??? ??? ??? ?box.className = "box";
?? ??? ??? ??? ??? ??? ?main.appendChild(box);
?? ??? ??? ??? ??? ??? ?var pic = document.createElement("div");
?? ??? ??? ??? ??? ??? ?pic.className = "pic";
?? ??? ??? ??? ??? ??? ?box.appendChild(pic);
?? ??? ??? ??? ??? ??? ?var Img = document.createElement("img");
?? ??? ??? ??? ??? ??? ?Img.src= "img/" + da.data[i].src;
?? ??? ??? ??? ??? ??? ?pic.appendChild(Img);
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?//再次調(diào)用給他定位
?? ??? ??? ??? ??? ?waterfall("main","box");
?? ??? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?}
?? ??? ?}
function waterfall(parent,box){
?? ??? ??? ?var oparent = document.getElementById(parent);? //main所有的class叫box的取出來(lái)
?? ??? ??? ?var oboxs= getByClass(oparent,box);
?? ??? ??? ?//console.log(obox.length);
?? ??? ??? ?//計(jì)算整個(gè)頁(yè)面顯示列數(shù)(頁(yè)面寬/box寬)
?? ??? ??? ?var oboxw = oboxs[0].offsetWidth;
?? ??? ??? ?var cols = Math.floor(document.documentElement.clientWidth/oboxw);
?? ??? ??? ?//設(shè)置main寬
?? ??? ??? ?var w = oparent.style.cssText = "width:"+oboxw *cols +"px;margin:0 auto";
?? ??? ??? ?//存放每列高度的數(shù)組
?? ??? ??? ?var harr = [];
?? ??? ??? ?for(var i=0; i<oboxs.length; i++){
?? ??? ??? ??? ?if(i<cols){
?? ??? ??? ??? ??? ?//獲取一組的高度
?? ??? ??? ??? ??? ?harr.push(oboxs[i].offsetHeight);
?? ??? ??? ??? ?}else{
?? ??? ??? ??? ??? ?////因?yàn)閙in方法只能第一組方法,不能對(duì)很多數(shù)組,所以用apply改變this指向
?? ??? ??? ??? ??? ?var hmin = Math.min.apply(null,harr);
?? ??? ??? ??? ??? ?var index = getIndex(harr,hmin);
?? ??? ??? ??? ??? ?oboxs[i].style.position = "absolute";
?? ??? ??? ??? ??? ?oboxs[i].style.top = hmin+"px";
?? ??? ??? ??? ??? ?//oboxs[i].style.left = oboxw*index +"px";
?? ??? ??? ??? ??? ?oboxs[i].style.left = oboxs[index].offsetLeft +"px";
?? ??? ??? ??? ??? ?//修改原來(lái)最小值:給它再賦值(把它原來(lái)的高+后面下面那個(gè)盒子的高)146+后面圖片高
?? ??? ??? ??? ??? ?harr[index] += oboxs[i].offsetHeight; ?
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?//console.log(harr);
?? ??? ?}
2017-11-20
?var da = {"data":[{"src":"1H.ico"},{"scr":"DD.ico"},{"src":"GM.ico"}]}; 里面的第二個(gè)src寫(xiě)錯(cuò)了!
2017-11-20
?另外建議把if(checkScrollSlide)改成?if(checkScrollSlide())