效果如图所示:

代码如下:
<template>
<div class="container">
<div id="box" ref="box">
<div
class="marquee-box"
ref="marquee"
@mouseover="menter"
@mouseleave="mleave"
>
<p ref="cmdlist" id="pWidth">平台提醒:注意数据安全,以免数据丢失。</p>
</div>
</div>
</div>
</template>
<script>
export default {
name: "HMessage",
data() {
return {
value: 0,
timer: "", //计时器
pwidth: 0, //公告文本的宽度
windowWidth: document.documentElement.clientWidth, // 设备屏幕的宽度
};
},
mounted() {
this.pwidth = [500, 0];
this.timer = setInterval(this.clickCommend, 20);
},
watch: {
value(newValue) {
const allWidth = parseInt(this.windowWidth) + parseInt(this.pwidth[0]);
if (newValue <= -allWidth) {
this.$refs.cmdlist.style.marginLeft = this.windowWidth + "px";
this.value = 0;
}
},
},
methods: {
clickCommend() {
const _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);
},
};
</script>
<style scoped lang="scss">
.container {
width: 100%;
margin-top: 100px;
}
#box {
width: 100%;
height: 100%;
position: relative;
}
.marquee-box {
position: relative;
width: 100%;
height: 100%;
}
#pWidth {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
display: flex;
align-items: center;
word-break: keep-all;
white-space: nowrap;
overflow: hidden;
font-family: 微软雅黑;
font-size: 0.83rem;
color: #f56c6c;
font-size: 30px;
}
::-webkit-scrollbar {
width: 0 !important;
}
::-webkit-scrollbar {
width: 0 !important;
height: 0;
}
</style>