第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

瀑布流實(shí)現(xiàn)

window.onload?=?function(){
	imgLocation('container',?'box');
	window.onscroll?=?function(){
		var?imgData?=?{
			"data":[
				{"src"?:?"1.jpg"},
				{"src"?:?"2.jpg"},
				{"src"?:?"3.jpg"},
				{"src"?:?"4.jpg"},
				{"src"?:?"5.jpg"},
				{"src"?:?"6.jpg"}
			]
		};
		if(checkFlag()){
			var?oParent?=?$('container');
			for(var?i?=?0;?i?<?imgData.data.length;?i++){
				var?createdBox?=?document.createElement('div');
				createdBox.className?=?'box';
				oParent.appendChild(createdBox);
				var?imgBox?=?document.createElement('div');
				imgBox.className?=?'box_img';
				createdBox.appendChild(imgBox);
				var?img?=?document.createElement('img');
				img.src?=?'img/'?+?imgData.data[i].src;
				imgBox.appendChild(img);
			}
		}
		imgLocation('container',?'box');
	};
};
/**
	判斷何時(shí)滾動(dòng)加載
*/
function?checkFlag(){
	var?oParent?=?$('container');
	var?oBoxs?=?getByClass(oParent,?'box');
	var?lastBoxDistance?=?oBoxs[oBoxs.length?-?1].offsetTop;
	var?scrollTop?=?document.documentElement.scrollTop?||?document.body.scrollTop;
	var?viewportHeight?=?document.documentElement.clientHeight?||?document.body.clientHeight;
	if(lastBoxDistance?<?(scrollTop?+?viewportHeight)){
		return?true;
	}
}
function?imgLocation(parent,?childClsName){
	var?oParent?=?$(parent);
	var?oBoxs?=?getByClass(oParent,?childClsName);
	//console.log(oBoxs);
	var?imgWidth?=?oBoxs[0].offsetWidth;
	var?cols?=?Math.floor(document.documentElement.clientWidth?/?imgWidth);
	oParent.style.cssText?=?"width:"?+?imgWidth?*?cols?+?"px;margin:0?auto";

	/*第一行盒子的高度集合*/
	var?boxHeightArr?=?[];
	for(var?i?=?0;?i?<?oBoxs.length;?i++){
		if(i?<?cols){
			boxHeightArr[i]?=?oBoxs[i].offsetHeight;?
		}else{
			//第一行中最小高度的值
			var?minHeight?=?Math.min.apply(null,??boxHeightArr);
			console.log(minHeight);
			var?indexOfMinHeight?=?getMinHeightIndex(boxHeightArr,?minHeight);
			console.log(indexOfMinHeight);
			oBoxs[i].style.position?=?'absolute';
			oBoxs[i].style.top?=?minHeight?+?'px';
			oBoxs[i].style.left?=?oBoxs[indexOfMinHeight].offsetLeft?+?'px';
			//更新高度
			boxHeightArr[indexOfMinHeight]?=?boxHeightArr[indexOfMinHeight]?+?oBoxs[i].offsetHeight;
		}
	}
}
function?getMinHeightIndex(boxHeightArr,?minHeight){
	for(var?height?in?boxHeightArr){
		if(boxHeightArr[height]?==?minHeight){
			return?height;
		}
	}
}
function?getByClass(parent,?childClsName){
	var?resultArr?=?[],
	?	allElements?=?parent.getElementsByTagName('*'),
	?	i?=?0;

	for(i?=?0;?i?<?allElements.length;?i++){
		if(allElements[i].className?==?childClsName){
			resultArr.push(allElements[i]);
		}
	}
	return?resultArr;
}
function?$(id){
	return?document.getElementById(id);
}

不錯(cuò)。。。。

正在回答

1 回答

我想問(wèn)如果數(shù)組里面的圖片都加載了一次要怎么停止呢,不想無(wú)限加載


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
瀑布流布局
  • 參與學(xué)習(xí)       97751    人
  • 解答問(wèn)題       756    個(gè)

瀑布流布局是網(wǎng)站比較流行的一種布局方式,教你實(shí)現(xiàn)三大方式

進(jìn)入課程

瀑布流實(shí)現(xiàn)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)