基于vue實(shí)現(xiàn)新聞自下往上滾動(dòng)效果(示例代碼)

如圖所示自下往上滾動(dòng)鼠標(biāo)放上暫停滾動(dòng) 鼠標(biāo)移出繼續(xù)滾動(dòng)
一、html:
<div class="newsList" @mouseover="mouseOver" @mouseout="mouseOut">
<ul id="con1" ref="con1" :class="{ anim: animate == true }">
<li v-for="(item, key) in items" :key="key" class="newsItem">
<img src="../../assets/img/icon.png" alt="" style="margin-top:5px;width:20px;height:20px">
<span>{{ item.title }}</span>
<span @click="getCode(item.qrCode)">查看></span>
</li>
</ul>
<div class="showCode" v-if="codeShow">
<p style="text-align:right;padding-right:10px;cursor:pointer" @click="codeShow=false">x</p>
<img :src="code" alt="">
<p>更多內(nèi)容可掃碼查看</p>
</div>
</div>
二.css動(dòng)畫(huà)
.newsList {
width: 90%;
margin: 10px auto;
height: 90px;
overflow: hidden;
font-size: 12px;
font-family: PingFang SC;
font-weight: 400;
line-height: 17px;
color: #ffffff;
/* background-color: red; */
}
.anim {
transition: all 1s;
margin-top: -30px;
}
#con1 li {
list-style: none;
line-height: 30px;
height: 30px;
}三、js代碼
mounted() {
this.timer=setInterval(this.scroll, 2000);
this.$api.newsList({
limit:12,
page:1
}).then(res=>{
this.items=res.data.records
})
},
methods: {
scroll() {
this.animate = true; // 因?yàn)樵谙⑾蛏蠞L動(dòng)的時(shí)候需要添加css3過(guò)渡動(dòng)畫(huà),所以這里需要設(shè)置true
setTimeout(() => {
// 這里直接使用了es6的箭頭函數(shù),省去了處理this指向偏移問(wèn)題,代碼也比之前簡(jiǎn)化了很多
this.items.push(this.items[0]); // 將數(shù)組的第一個(gè)元素添加到數(shù)組的
this.items.shift(); //刪除數(shù)組的第一個(gè)元素
this.animate = false; // margin-top 為0 的時(shí)候取消過(guò)渡動(dòng)畫(huà),實(shí)現(xiàn)無(wú)縫滾動(dòng)
}, 1000);
},
getCode(qrCode){
this.code=qrCode
this.codeShow=true
},
mouseOver(){
console.log('鼠標(biāo)懸停')
// this.animate = false;
clearInterval(this.timer)
},
mouseOut(){
// this.animate = true;
this.timer=setInterval(this.scroll, 2000);
}
},到此這篇關(guān)于vue新聞自下往上滾動(dòng)效果的文章就介紹到這了,更多相關(guān)vue新聞滾動(dòng)效果內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3使用Univer Docs創(chuàng)建在線編輯Excel的示例代碼
本文介紹了如何在Vue3項(xiàng)目中集成UniverDocs,一個(gè)基于Luckysheet的企業(yè)文檔與數(shù)據(jù)協(xié)同解決方案,指導(dǎo)了從安裝到在頁(yè)面中使用的步驟,以及注意事項(xiàng),如數(shù)據(jù)格式轉(zhuǎn)換和二次開(kāi)發(fā)的靈活性,需要的朋友可以參考下2025-04-04
Vue 報(bào)錯(cuò)TypeError: this.$set is not a function 的解決方法
這篇文章主要介紹了Vue 報(bào)錯(cuò)TypeError: this.$set is not a function 的解決方法,分享給大家,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12
淺談mint-ui loadmore組件注意的問(wèn)題
下面小編就為大家?guī)?lái)一篇淺談mint-ui loadmore組件注意的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11
vue實(shí)現(xiàn)拖拽的簡(jiǎn)單案例 不超出可視區(qū)域
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)拖拽的簡(jiǎn)單案例,不超出可視區(qū)域,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
element-ui滾動(dòng)條el-scrollbar置底方式
這篇文章主要介紹了element-ui滾動(dòng)條el-scrollbar置底方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08

