使用Vue實(shí)現(xiàn)瀑布流的示例代碼
1.每個(gè)色塊寬度一致,高度自適應(yīng)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="user-scalable=0">
<title>Vertical Line</title>
<link rel="stylesheet" href="./common/css/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<style>
.item-move {
transition: all .5s cubic-bezier(.55, 0, .1, 1);
-webkit-transition: all .5s cubic-bezier(.55, 0, .1, 1);
}
</style>
</head>
<body>
<div id="app">
<waterfall :align="align" :line-gap="200" :min-line-gap="100" :max-line-gap="220" :single-max-width="300"
:watch="items" @reflowed="reflowed" ref="waterfall">
<!-- each component is wrapped by a waterfall slot -->
<waterfall-slot v-for="(item, index) in items" :width="item.width" :height="item.height" :order="index"
:key="item.index" move-class="item-move">
<div class="item" :style="item.style" :index="item.index"></div>
</waterfall-slot>
</waterfall>
</div>
<script src="https://cdn.jsdelivr.net/vue/2.2.6/vue.min.js"></script>
<script src="http://app.moptym.com/cdn/vue-waterfall/vue-waterfall.min.js"></script>
<script src="./common/js/item-factory.js"></script>
<script>
var app = new Vue({
el: '#app',
components: {
'waterfall': Waterfall.waterfall,
'waterfall-slot': Waterfall.waterfallSlot
},
data: {
align: 'center',
items: ItemFactory.get(100),
isBusy: false
},
methods: {
addItems: function () {
if (!this.isBusy && this.items.length < 500) {
this.isBusy = true
this.items.push.apply(this.items, ItemFactory.get(50))
}
},
shuffle: function () {
this.items.sort(function () {
return Math.random() - 0.5
})
},
reflowed: function () {
this.isBusy = false
}
}
})
document.body.addEventListener('click', function () {
app.shuffle()
// app.$refs.waterfall.$emit('reflow') // manually trigger reflow action
}, false)
window.addEventListener('scroll', function () {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
if (scrollTop + window.innerHeight >= document.body.clientHeight) {
app.addItems()
}
})
</script>
</body>
</html>
如圖所示:

2.每個(gè)色塊高度一致,寬度自適應(yīng)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="user-scalable=0">
<title>Horizontal Line</title>
<link rel="stylesheet" href="./common/css/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<style>
.item-move {
transition: all .5s cubic-bezier(.55, 0, .1, 1);
-webkit-transition: all .5s cubic-bezier(.55, 0, .1, 1);
}
</style>
</head>
<body>
<div id="app">
<waterfall :line="line" :line-gap="200" :min-line-gap="180" :max-line-gap="220" :watch="items" @reflowed="reflowed"
ref="waterfall">
<!-- each component is wrapped by a waterfall slot -->
<waterfall-slot v-for="(item, index) in items" :width="item.width" :height="item.height" :order="index"
:key="item.index" move-class="item-move">
<div class="item" :style="item.style" :index="item.index"></div>
</waterfall-slot>
</waterfall>
</div>
<script src="https://cdn.jsdelivr.net/vue/2.2.6/vue.min.js"></script>
<script src="http://app.moptym.com/cdn/vue-waterfall/vue-waterfall.min.js"></script>
<script src="./common/js/item-factory.js"></script>
<script>
var app = new Vue({
el: '#app',
components: {
'waterfall': Waterfall.waterfall,
'waterfall-slot': Waterfall.waterfallSlot
},
data: {
line: 'h',
items: ItemFactory.get(100),
isBusy: false
},
methods: {
addItems: function () {
if (!this.isBusy && this.items.length < 500) {
this.isBusy = true
this.items.push.apply(this.items, ItemFactory.get(50))
}
},
shuffle: function () {
this.items.sort(function () {
return Math.random() - 0.5
})
},
reflowed: function () {
this.isBusy = false
}
}
})
document.body.addEventListener('click', function () {
app.shuffle()
// app.$refs.waterfall.$emit('reflow') // manually trigger reflow action
}, false)
window.addEventListener('scroll', function () {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
if (scrollTop + window.innerHeight >= document.body.clientHeight) {
app.addItems()
}
})
</script>
</body>
</html>
如圖所示:

3.寬高不限制,每個(gè)色塊順著排
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="user-scalable=0">
<title>Vertical Line With Grow</title>
<link rel="stylesheet" href="./common/css/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<style>
.item-move {
transition: all .5s cubic-bezier(.55, 0, .1, 1);
-webkit-transition: all .5s cubic-bezier(.55, 0, .1, 1);
}
</style>
</head>
<body>
<div id="app">
<waterfall :grow="grow" :watch="items" @reflowed="reflowed" ref="waterfall">
<!-- each component is wrapped by a waterfall slot -->
<waterfall-slot v-for="(item, index) in items" :width="item.width" :height="item.height" :order="index"
:key="item.index" move-class="item-move">
<div class="item" :style="item.style" :index="item.index"></div>
</waterfall-slot>
</waterfall>
</div>
<script src="https://cdn.jsdelivr.net/vue/2.2.6/vue.min.js"></script>
<script src="http://app.moptym.com/cdn/vue-waterfall/vue-waterfall.min.js"></script>
<script src="./common/js/item-factory.js"></script>
<script>
var app = new Vue({
el: '#app',
components: {
'waterfall': Waterfall.waterfall,
'waterfall-slot': Waterfall.waterfallSlot
},
data: {
grow: [3, 2, 1, 2],
items: ItemFactory.get(100),
isBusy: false
},
methods: {
addItems: function () {
if (!this.isBusy && this.items.length < 500) {
this.isBusy = true
this.items.push.apply(this.items, ItemFactory.get(50))
}
},
shuffle: function () {
this.items.sort(function () {
return Math.random() - 0.5
})
},
reflowed: function () {
this.isBusy = false
}
}
})
document.body.addEventListener('click', function () {
app.shuffle()
// app.$refs.waterfall.$emit('reflow') // manually trigger reflow action
}, false)
window.addEventListener('scroll', function () {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
if (scrollTop + window.innerHeight >= document.body.clientHeight) {
app.addItems()
}
})
</script>
</body>
</html>
如圖所示:

到此這篇關(guān)于使用Vue實(shí)現(xiàn)瀑布流的示例代碼的文章就介紹到這了,更多相關(guān)Vue瀑布流內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue+element-ui+sortable.js實(shí)現(xiàn)表格拖拽功能
這篇文章主要為大家詳細(xì)介紹了vue+element-ui+sortable.js實(shí)現(xiàn)表格拖拽功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Vue.2.0.5實(shí)現(xiàn)Class 與 Style 綁定的實(shí)例
本篇文章主要介紹了Vue.2.0.5實(shí)現(xiàn)Class 與 Style 綁定的實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
keep-alive include和exclude無(wú)效問(wèn)題及解決
這篇文章主要介紹了keep-alive include和exclude無(wú)效問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
vue項(xiàng)目中canvas實(shí)現(xiàn)截圖功能
這篇文章主要為大家詳細(xì)介紹了vue項(xiàng)目中canvas實(shí)現(xiàn)截圖功能,截取圖片的一部分,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
nginx部署訪問(wèn)vue-cli搭建的項(xiàng)目的方法
本篇文章主要介紹了nginx部署訪問(wèn)vue-cli搭建的項(xiàng)目的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
解決IE11 vue +webpack 項(xiàng)目中數(shù)據(jù)更新后頁(yè)面沒(méi)有刷新的問(wèn)題
今天小編就為大家分享一篇解決IE11 vue +webpack 項(xiàng)目中數(shù)據(jù)更新后頁(yè)面沒(méi)有刷新的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09
vue實(shí)現(xiàn)數(shù)字變換動(dòng)畫的示例代碼
本文主要介紹了vue實(shí)現(xiàn)數(shù)字變換動(dòng)畫的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04

