<template>
<div id="box">
<div class="item" v-for="list in ceoPhoto">
<img :src="list.picUrl" alt="">
</div>
</div>
</template>
<script>
import axios from "axios"
export default {
name: "Ceo",
data () {
return {
pullRefreshss:true,
ceoPhoto:[
{
"picUrl":"../../../static/image/demo/1.jpg"
},{
"picUrl":"../../../static/image/demo/2.jpg"
},{
"picUrl":"../../../static/image/demo/3.jpg"
},{
"picUrl":"../../../static/image/demo/4.jpg"
},{
"picUrl":"../../../static/image/demo/5.jpg"
},{
"picUrl":"../../../static/image/demo/6.jpg"
},{
"picUrl":"../../../static/image/demo/7.jpg"
},{
"picUrl":"../../../static/image/demo/8.jpg"
},{
"picUrl":"../../../static/image/demo/9.jpg"
},{
"picUrl":"../../../static/image/demo/10.jpg"
},{
"picUrl":"../../../static/image/demo/11.jpg"
}
],
ceoPhotoS:[
{
"picUrl":"../../../static/image/demo/12.jpg"
},{
"picUrl":"../../../static/image/demo/13.jpg"
},{
"picUrl":"../../../static/image/demo/14.jpg"
},{
"picUrl":"../../../static/image/demo/15.jpg"
},{
"picUrl":"../../../static/image/demo/16.jpg"
},{
"picUrl":"../../../static/image/demo/17.jpg"
},{
"picUrl":"../../../static/image/demo/18.jpg"
},{
"picUrl":"../../../static/image/demo/19.jpg"
},{
"picUrl":"../../../static/image/demo/20.jpg"
}
]
}
},
created () {
},
watch: {},
mounted(){
this.init();
},
methods:{
init(){
this.waterFall();
this.pullRefresh();
},
waterFall(){
var box = document.getElementById("box");
var items = box.children;
// 10
var gap = 10;
// 1- = /
var pageWidth = this.getClient().width;
var itemWidth = items[0].offsetWidth;
var columns = parseInt(pageWidth / (itemWidth + gap));
var arr = [];
for (var i = 0; i < items.length; iPP) {
if (i < columns) {
// 2-
items[i].style.top = 0;
items[i].style.left = (itemWidth + gap) * i + "px";
arr.push(items[i].offsetHeight);
} else {
//
// 3-
var minHeight = arr[0];
var index = 0;
for (var j = 0; j < arr.length; jPP) {
if (minHeight > arr[j]) {
minHeight = arr[j];
index = j;
}
}
// 4-
// top + gap
items[i].style.top = arr[index] + gap + "px";
// left
items[i].style.left = items[index].offsetLeft + "px";
// 5-
// = + +
arr[index] = arr[index] + items[i].offsetHeight + gap;
}
}
this.pullRefreshss = true;
},
getClient(){
return {
width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
}
},
//
getScrollTop(){
var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
if (document.body) {
bodyScrollTop = document.body.scrollTop;
}
if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
return scrollTop;
},
//
getScrollHeight(){
var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
if (document.body) {
bodyScrollHeight = document.body.scrollHeight;
}
if (document.documentElement) {
documentScrollHeight = document.documentElement.scrollHeight;
}
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
return scrollHeight;
},
//
getWindowHeight(){
var windowHeight = 0;
if (document.compatMode == "CSS1Compat") {
windowHeight = document.documentElement.clientHeight;
} else {
windowHeight = document.body.clientHeight;
}
return windowHeight;
},
pullRefresh(){
var _this = this;
$(window).scroll(function () {
_this.scrollChange();
let scrollTop = $(this).scrollTop();
if(scrollTop>=50){
_this.scrollTop = true;
}else{
_this.scrollTop = false;
}
})
},
scrollChange(){
this.scollY = this.getScrollTop() + this.getWindowHeight() - this.getScrollHeight();
// false
if(this.scollY >= -50){
if(!this.pullRefreshss){
return false;
}
this.initpush();
}else{
this.pullRefreshss = true;
}
},
initpush(){
this.pullRefreshss = false;
for(var i = 0 ; i<this.ceoPhotoS.length;iPP){
this.ceoPhoto.push(this.ceoPhotoS[i]);
}
this.waterFall();
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
* {
margin: 0;
padding: 0;
position: relative;
}
img {
width: 220px;
display: block;
}
.item {
box-shadow: 2px 2px 2px -sharp999;
position: absolute;
}
</style>
effect displayed:
,: