vue實現橫屏滾動公告效果
更新時間:2022年04月08日 10:09:27 作者:張艷偉_Laura
這篇文章主要為大家詳細介紹了vue實現橫屏滾動公告效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現橫屏滾動公告效果的具體代碼,供大家參考,具體內容如下
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="">累計練習時長1小時,可以獲得1次抽獎機會,獎品有。。。。。 ? ? ? </p> ? ? </div> ? </div> </template>
JS文件內容
export default { ? name: 'HelloWorld', ? data () { ? ? return { ? ? ? value: 0, ? ? ? timer: '',//計時器 ? ? ? pwidth:0,//公告文本的寬度 ? ? ? windowWidth:document.documentElement.clientWidth,// 設備屏幕的寬度 ? ? ? } ? ? }, ? 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>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
VUE使用DXFParser組件解析dxf文件生成圖片的操作代碼
這篇文章主要介紹了VUE使用DXFParser組件解析dxf文件生成圖片的操作代碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-09-09Vant中List組件immediate-check=false無效的解決
這篇文章主要介紹了Vant中List組件immediate-check=false無效的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01