<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
*{padding: 0;margin: 0;}
#main{position: relative;margin: 0 auto;}
.box{padding: 15px 0 0 15px;float: left;}
.pic{padding: 10px;border: 1px solid #ccc;border-radius: 5px;box-shadow: 0 0 5px #ccc;}
.pic img{width: 165px;height: auto;}
.imgDg{position: fixed;top: 0px;left: 0px;background: rgba(0,0,0,0.5);z-index: 9;}
.imgDiv .pic{z-index: 10;width: 500px;height: 350px;background: #FFFFFF;position: fixed;}
.imgDiv .pic img{width: 100%;height: 100%;}
.imgDiv{position: fixed;}
</style>
<body>
<div id="main">
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/cat.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/cat.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/cat.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu02.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
</div>
</body>
<script type="text/javascript">
window.onload = function(){
waterfall('main','box');
var dataInt = {
'data':[
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'}
]
};
window.onscroll = function(){
if(checkScrollSlide){
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 = dataInt.data[i].src;
oPic.appendChild(oImg)
waterfall('main','box')
}
}
// checkScrollSlide()
}
// clickImg('main','img')
}
function checkScrollSlide(){
var oParent = document.getElementById('main');
var oBoxs = getByClass(oParent,'box');
var lastBoxH = oBoxs[oBoxs.length-1].offsetTop + Math.floor((oBoxs[oBoxs.length-1].offsetTop)/2)
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var height = document.body.clientHeight||document.documentElement.clientHeight;
return (lastBoxH<scrollTop+height)?true:false;
}
// function clickImg(d,tag){
var img = [];
// var imgParent = document.getElementById(d);
// imgTag = imgParent.getElementsByClassName('box');
// for(var i=0;i<imgTag.length;i++){
// imgTag[i].setAttribute('onclick','showImg(this)');
// }
//
// }
// function showImg(e){
// var pic = e.getElementsByClassName('pic');
// var imgDg = document.createElement('div');
// var pageW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
// var pageH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
// imgDg.style.width = pageW +'px';
// imgDg.style.height = pageH +'px';
// imgDg.className = 'imgDg';
// e.className = 'box imgDiv';
// e.style.cssText = 'top:'+((pageW-500)/2)+'px;'+'left:' + ((pageW-300)/2)+'px';
// e.appendChild(imgDg);
// }
function waterfall(parent,box){
var oParent = document.getElementById(parent);
var oBoxs = getByClass(oParent,box);
console.log(oBoxs);
//计算整个页面显示的列数(页面宽度/box宽度)
var oBoxW = oBoxs[0].offsetWidth;
var pageW = window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
var cols = Math.floor(pageW/oBoxW);
//设置main的width
oParent.style.cssText = 'width:'+cols*oBoxW+'px;margin:0 auto';
var hArr = []; //存放每一列的高度
for(var i = 0;i<oBoxs.length;i++){
if(i<cols){
hArr.push(oBoxs[i].offsetHeight)
}else{
var minH = Math.min.apply(null,hArr);
var index = getMinhIndex(hArr,minH);
oBoxs[i].style.position = 'absolute';
oBoxs[i].style.top = minH+'px';
oBoxs[i].style.left = oBoxW*index +'px';
//oBoxs[i].style.left = oBoxs[index].offsetWidth+'px';
hArr[index] += oBoxs[i].offsetHeight; //最小加上 加上图片的高
}
}
console.log(hArr);
}
//获取多少个box
function getByClass(parent,clsName){
var boxArr = new Array(),
oElements = parent.getElementsByTagName('*');
for(var i = 0;i<oElements.length;i++){
if(oElements[i].className == clsName){
boxArr.push(oElements[i])
}
}
return boxArr
}
//计算出数组最小值的索引位置
function getMinhIndex(arr,val){
for(var i in arr){
if(arr[i]==val){
return i
}
}
}
</script>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
*{padding: 0;margin: 0;}
#main{position: relative;margin: 0 auto;}
.box{padding: 15px 0 0 15px;float: left;}
.pic{padding: 10px;border: 1px solid #ccc;border-radius: 5px;box-shadow: 0 0 5px #ccc;}
.pic img{width: 165px;height: auto;}
.imgDg{position: fixed;top: 0px;left: 0px;background: rgba(0,0,0,0.5);z-index: 9;}
.imgDiv .pic{z-index: 10;width: 500px;height: 350px;background: #FFFFFF;position: fixed;}
.imgDiv .pic img{width: 100%;height: 100%;}
.imgDiv{position: fixed;}
</style>
<body>
<div id="main">
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/cat.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/cat.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/cat.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/3/11.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu02.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/10/leaf.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu01.jpg"/>
</div>
</div>
<div class='box'>
<div class='pic'>
<img src="JavaScript网页特效实例大全/JavaScript网页特效实例大全/6/kele.jpg"/>
</div>
</div>
</div>
</body>
<script type="text/javascript">
window.onload = function(){
waterfall('main','box');
var dataInt = {
'data':[
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'},
{'src':'JavaScript网页特效实例大全/JavaScript网页特效实例大全/5/tu03.jpg'}
]
};
window.onscroll = function(){
if(checkScrollSlide){
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 = dataInt.data[i].src;
oPic.appendChild(oImg)
waterfall('main','box')
}
}
// checkScrollSlide()
}
// clickImg('main','img')
}
function checkScrollSlide(){
var oParent = document.getElementById('main');
var oBoxs = getByClass(oParent,'box');
var lastBoxH = oBoxs[oBoxs.length-1].offsetTop + Math.floor((oBoxs[oBoxs.length-1].offsetTop)/2)
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var height = document.body.clientHeight||document.documentElement.clientHeight;
return (lastBoxH<scrollTop+height)?true:false;
}
// function clickImg(d,tag){
var img = [];
// var imgParent = document.getElementById(d);
// imgTag = imgParent.getElementsByClassName('box');
// for(var i=0;i<imgTag.length;i++){
// imgTag[i].setAttribute('onclick','showImg(this)');
// }
//
// }
// function showImg(e){
// var pic = e.getElementsByClassName('pic');
// var imgDg = document.createElement('div');
// var pageW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
// var pageH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
// imgDg.style.width = pageW +'px';
// imgDg.style.height = pageH +'px';
// imgDg.className = 'imgDg';
// e.className = 'box imgDiv';
// e.style.cssText = 'top:'+((pageW-500)/2)+'px;'+'left:' + ((pageW-300)/2)+'px';
// e.appendChild(imgDg);
// }
function waterfall(parent,box){
var oParent = document.getElementById(parent);
var oBoxs = getByClass(oParent,box);
console.log(oBoxs);
//计算整个页面显示的列数(页面宽度/box宽度)
var oBoxW = oBoxs[0].offsetWidth;
var pageW = window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
var cols = Math.floor(pageW/oBoxW);
//设置main的width
oParent.style.cssText = 'width:'+cols*oBoxW+'px;margin:0 auto';
var hArr = []; //存放每一列的高度
for(var i = 0;i<oBoxs.length;i++){
if(i<cols){
hArr.push(oBoxs[i].offsetHeight)
}else{
var minH = Math.min.apply(null,hArr);
var index = getMinhIndex(hArr,minH);
oBoxs[i].style.position = 'absolute';
oBoxs[i].style.top = minH+'px';
oBoxs[i].style.left = oBoxW*index +'px';
//oBoxs[i].style.left = oBoxs[index].offsetWidth+'px';
hArr[index] += oBoxs[i].offsetHeight; //最小加上 加上图片的高
}
}
console.log(hArr);
}
//获取多少个box
function getByClass(parent,clsName){
var boxArr = new Array(),
oElements = parent.getElementsByTagName('*');
for(var i = 0;i<oElements.length;i++){
if(oElements[i].className == clsName){
boxArr.push(oElements[i])
}
}
return boxArr
}
//计算出数组最小值的索引位置
function getMinhIndex(arr,val){
for(var i in arr){
if(arr[i]==val){
return i
}
}
}
</script>
</html>