img {
border:none;
display:block
}
.container {
width:1000px;
margin:0 auto;
position:relative;
}
.container .item {
position:absolute;
box-sizing:border-box;
}
.item img {
width:240px;
padding:3px;
border:1px solid #eee;
box-sizing:border-box;
box-shadow:0 0 5px;
border-radius:5px;
}
@media screen and (max-width:1200px) {
.container {
width:800px !important;
margin:0 auto;
position:relative;
}
}@media only screen and(min-width:1200px) and (max-width:1920px) {
.container {
width:1000px !important;
margin:0 auto;
position:relative;
}
}注意:在上边的图片没法弄,大家可以下下来,写自己的数组数据图片如:[{src:'path'}];还有就是显示的不是等高的,这是因为没有图片;
★★★实现了自适应 在屏幕为1200-1920的时候,container为1000此时显示,此时会计算出显示4列
当屏幕为1200一下的时候,container为800,此时会计算显示出三列
调用方法:
var wf = new waterfall({
containerw: cw,//最外边容器的宽度如:1000
childw: itemw,//字容器的宽度如:240
childlist: items,//传入子容器的数组(就是先默认显示几个子容器)
imglist: imglist//传入图片数据[{src:'path'}]
})
wf.init()