vue實(shí)現(xiàn)列表無(wú)縫滾動(dòng)
本文實(shí)例為大家分享了vue實(shí)現(xiàn)列表無(wú)縫滾動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下
HTML部分代碼
<template>
<div id="box" class="wrapper">
<div class="contain" id="con1" ref="con1" :class="{anim:animate==true}">
<List
v-for="(item,index) in cloudList"
:key="index"
:listData="item"
:index="index"
:date="date"
></List>
</div>
</div>
</template>
List是單個(gè)列表組件,也可以替換成li。
css部分代碼
<style scoped>
.wrapper {
width: 96vw;
height: 90vh;
position: absolute;
left: 2vw;
top: 1rem;
overflow: hidden;
}
.contain > div:nth-child(2n) {//這個(gè)樣式是我這個(gè)項(xiàng)目所需,與無(wú)縫滾動(dòng)無(wú)直接關(guān)系,可以忽略
margin-left: 2vw;
}
.anim {
transition: all 0.5s;
margin-top: -7vh;
}
</style>
我的List組件是設(shè)置了float:left的,所以id="con1"的div是沒(méi)有高度的
js部分代碼
<script>
import List from './List';
export default {
name: 'Contain',
data () {
return {
cloudList: [],//數(shù)組用來(lái)存放列表數(shù)據(jù)
date: '',//最新數(shù)據(jù)更新日期
animate: false,
time: 3000,//定時(shí)滾動(dòng)的間隙時(shí)間
setTimeout1: null,
setInterval1: null
};
},
components: {
List
},
methods: {
// 獲取json數(shù)據(jù)并且更新日期
getCloudListData () {
const _this = this;
_this.$api.getCloudListData().then(res => {
_this.cloudList = res;
});
var newDate = new Date();
_this.date = _this.dateFtt('yyyy-MM-dd hh:mm:ss', newDate);
},
// 日期格式化
dateFtt (fmt, date) {
var o = {
'M+': date.getMonth() + 1, // 月份
'd+': date.getDate(), // 日
'h+': date.getHours(), // 小時(shí)
'm+': date.getMinutes(), // 分
's+': date.getSeconds(), // 秒
'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
S: date.getMilliseconds() // 毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
(date.getFullYear() + '').substr(4 - RegExp.$1.length)
);
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length === 1
? o[k]
: ('00' + o[k]).substr(('' + o[k]).length)
);
}
}
return fmt;
},
// 滾動(dòng)
scroll () {
const _this = this;
_this.animate = true;
clearTimeout(_this.setTimeout1);
_this.setTimeout1 = setTimeout(() => {
var parent = document.getElementById('con1');
var first = document.getElementById('con1').children[0];
var second = document.getElementById('con1').children[1];
parent.removeChild(first);
parent.removeChild(second);
parent.appendChild(first);
parent.appendChild(second);
_this.animate = false;
}, 500);
}
},
created () {
const _this = this;
_this.getCloudListData();
//定時(shí)器每隔24小時(shí)更新一次數(shù)據(jù)
setInterval(() => {
_this.getCloudListData();
}, 24 * 60 * 60 * 1000);
},
mounted () {
const _this = this;
var contain = document.getElementById('box');
_this.setInterval1 = setInterval(_this.scroll, _this.time);
var setInterval2 = null;
// 鼠標(biāo)移入滾動(dòng)區(qū)域停止?jié)L動(dòng)
contain.onmouseenter = function () {
clearInterval(_this.setInterval1);
var count = 0;
// 如果鼠標(biāo)超過(guò)十秒不動(dòng) 就啟動(dòng)滾動(dòng)
setInterval2 = setInterval(function () {
count++;
if (count === 10) {
_this.scroll();
_this.setInterval1 = setInterval(_this.scroll, _this.time);
}
}, 1000);
//鼠標(biāo)一動(dòng)就停止?jié)L動(dòng)并且計(jì)數(shù)count置為0
contain.onmousemove = function () {
count = 0;
clearInterval(_this.setInterval1);
};
};
// 鼠標(biāo)移出滾動(dòng)區(qū)域
contain.onmouseleave = function () {
clearInterval(setInterval2);
clearInterval(_this.setInterval1);
_this.scroll();
_this.setInterval1 = setInterval(_this.scroll, _this.time);
};
}
};
</script>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue條件渲染列表渲染原理示例詳解
- antd vue表格可編輯單元格以及求和實(shí)現(xiàn)方式
- vue3實(shí)現(xiàn)無(wú)縫滾動(dòng)組件的示例代碼
- vue實(shí)現(xiàn)無(wú)縫滾動(dòng)的示例詳解
- vue實(shí)現(xiàn)無(wú)縫滾動(dòng)手摸手教程
- vue實(shí)現(xiàn)消息向上無(wú)縫滾動(dòng)效果
- vue實(shí)現(xiàn)無(wú)限消息無(wú)縫滾動(dòng)
- vue實(shí)現(xiàn)簡(jiǎn)單無(wú)縫滾動(dòng)效果
- vue實(shí)現(xiàn)列表無(wú)縫滾動(dòng)效果
- vue實(shí)現(xiàn)列表垂直無(wú)縫滾動(dòng)
- el-table動(dòng)態(tài)渲染列、可編輯單元格、虛擬無(wú)縫滾動(dòng)的實(shí)現(xiàn)
相關(guān)文章
vue項(xiàng)目搭建以及全家桶的使用詳細(xì)教程(小結(jié))
這篇文章主要介紹了vue項(xiàng)目搭建以及全家桶的使用詳細(xì)教程(小結(jié)),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
Vue結(jié)合ElementUI上傳Base64編碼后的圖片實(shí)例
這篇文章主要介紹了Vue結(jié)合ElementUI上傳Base64編碼后的圖片實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
ElementUI表單驗(yàn)證validate和validateField的使用及區(qū)別
Element-UI作為前端框架,最常使用到的就是表單驗(yàn)證,下面這篇文章主要給大家介紹了關(guān)于ElementUI表單驗(yàn)證validate和validateField的使用及區(qū)別,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
vant-ui框架的一個(gè)bug(解決切換后onload不觸發(fā))
這篇文章主要介紹了vant-ui框架的一個(gè)bug(解決切換后onload不觸發(fā)),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
VueJs使用Amaze ui調(diào)整列表和內(nèi)容頁(yè)面
這篇文章主要介紹了VueJs 填坑日記之使用Amaze ui調(diào)整列表和內(nèi)容頁(yè)面,需要的朋友可以參考下2017-11-11
基于element-ui封裝可搜索的懶加載tree組件的實(shí)現(xiàn)
這篇文章主要介紹了基于element-ui封裝可搜索的懶加載tree組件的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
Vue3獲取DOM節(jié)點(diǎn)的3種方式實(shí)例
Vue本來(lái)無(wú)需操作DOM來(lái)更新界面,而且Vue也不推薦我們直接操作DOM,但是我們非要拿到DOM操作DOM怎么辦,下面這篇文章主要給大家介紹了關(guān)于Vue3獲取DOM節(jié)點(diǎn)的3種方式,需要的朋友可以參考下2023-02-02
Vue-router 中hash模式和history模式的區(qū)別
這篇文章主要介紹了Vue-router 中hash模式和history模式的區(qū)別,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07

