vue實現(xiàn)橫屏滾動公告效果
更新時間:2022年04月08日 10:09:27 作者:張艷偉_Laura
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)橫屏滾動公告效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)橫屏滾動公告效果的具體代碼,供大家參考,具體內(nèi)容如下

HTML文件
<template> ? <div id="box" ref="box"> ? ? <div class="marquee-box" ref="marquee" @mouseover="menter" @mouseleave="mleave"> ? ? ? <p ref="cmdlist" id="pWidth"> ? ? ? ? <img style="width: 12px;height: 12px" src="../assets/logo.png" alt="">累計練習(xí)時長1小時,可以獲得1次抽獎機(jī)會,獎品有。。。。。 ? ? ? </p> ? ? </div> ? </div> </template>
JS文件內(nèi)容
export default {
? name: 'HelloWorld',
? data () {
? ? return {
? ? ? value: 0,
? ? ? timer: '',//計時器
? ? ? pwidth:0,//公告文本的寬度
? ? ? windowWidth:document.documentElement.clientWidth,// 設(shè)備屏幕的寬度
? ? ? }
? ? },
? mounted() {
? ? let element = this.$refs.cmdlist;
? ? this.pwidth = document.defaultView.getComputedStyle(element,'').width.split('px');
? ? this.timer = setInterval(this.clickCommend, 20);
? },
??
? watch:{
? ? value(newValue, oldValue) {
? ? ? let allWidth= parseInt(this.windowWidth)+parseInt(this.pwidth[0]);
? ? ? if(newValue <= -allWidth){
? ? ? ? this.$refs.cmdlist.style.marginLeft = this.windowWidth+"px";
? ? ? ? this.value = 0;
? ? ? }
? ? },
? },
??
? methods:{
? ? clickCommend(e) {
? ? ? let _this = this;
? ? ? this.$nextTick(() => {
? ? ? ? this.value -=1;
? ? ? ? this.$refs.cmdlist.style.marginLeft = _this.windowWidth+this.value+"px";
? ? ? });
? ? },
? ? menter(){
? ? ? clearInterval(this.timer);
? ? },
? ? mleave(){
? ? ? this.timer = setInterval(this.clickCommend, 20);
? ? },
? },
? beforeDestroy() {
? ? clearInterval(this.timer);
? }
}CSS樣式
<style scoped>
#box {
? width: 100%;
? height: 50px;
? margin-top: 50px;
? position: relative;
}
.marquee-box ?{
? position: relative;
? width: 100%;
? height: 100%;
? overflow:auto;
? background-color: #f8f8f8;
}
#pWidth{
? width: 100%;
? height: 50px;
? padding: 0;
? margin: 0;
? line-height: 50px;
? display: block;
? word-break: keep-all;
? white-space: nowrap;
? overflow:hidden;
? font-family: 微軟雅黑; fontSize:14px;
? background-color: #f8f8f8
}
::-webkit-scrollbar {
? width: 0 !important;
}
::-webkit-scrollbar {
? width: 0 !important;height: 0;
}
</style>以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue2.0嵌套路由實現(xiàn)豆瓣電影分頁功能(附demo)
這篇文章主要介紹了vue2.0嵌套路由實現(xiàn)豆瓣電影分頁功能(附demo),這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下。2017-03-03
Vue中登錄驗證成功后保存token,并每次請求攜帶并驗證token操作
這篇文章主要介紹了Vue中登錄驗證成功后保存token,并每次請求攜帶并驗證token操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
vue 實現(xiàn)axios攔截、頁面跳轉(zhuǎn)和token 驗證
這篇文章主要介紹了vue 實現(xiàn)axios攔截、頁面跳轉(zhuǎn)和token 驗證,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07
vue2中的keep-alive使用總結(jié)及注意事項
vue2.0提供了一個keep-alive組件用來緩存組件,避免多次加載相應(yīng)的組件,減少性能消耗。本文給大家介紹vue2中的keep-alive使用總結(jié)及注意事項,需要的朋友參考下吧2017-12-12

