<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- 確定列數(shù) = 頁面的寬度 / 圖片的寬度
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; i++) {
if (i < columns) {
// 2- 確定第一行
items[i].style.top = 0;
items[i].style.left = (itemWidth + gap) * i + 'px';
arr.push(items[i].offsetHeight);
} else {
// 其他行
// 3- 找到數(shù)組中最小高度 和 它的索引
var minHeight = arr[0];
var index = 0;
for (var j = 0; j < arr.length; j++) {
if (minHeight > arr[j]) {
minHeight = arr[j];
index = j;
}
}
// 4- 設(shè)置下一行的第一個(gè)盒子位置
// top值就是最小列的高度 + gap
items[i].style.top = arr[index] + gap + 'px';
// left值就是最小列距離左邊的距離
items[i].style.left = items[index].offsetLeft + 'px';
// 5- 修改最小列的高度
// 最小列的高度 = 當(dāng)前自己的高度 + 拼接過來的高度 + 間隙的高度
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,防止多次請(qǐng)求
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;i++){
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 #999;
position: absolute;
}
</style>
顯示出來的效果:
再次請(qǐng)求時(shí)蓋住了第一個(gè)圖片,因?yàn)榻壎▎栴}求解決:
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。