vue实现横屏滚动公告效果
更新时间:2022-04-08 11:12:36 作者:佚名 我要评论(0)
本文实例为大家分享了vue实现横屏滚动公告效果的具体代码,供大家参考,具体内容如下
HTML文件
<template>
? <div id="box" ref="box">
? ?
HTML文件
<template>
? <div id="box" ref="box">
? ?
本文实例为大家分享了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实现跑马灯样式文字横向滚动
- Vue中利用better-scroll组件实现横向滚动功能
- vue使用better-scroll实现横向滚动的方法实例
- Vue替代marquee标签超出宽度文字横向滚动效果
- Vue中消息横向滚动时setInterval清不掉的问题及解决方法
- Vue.js+cube-ui(Scroll组件)实现类似头条效果的横向滚动导航条
- vue实现公告栏文字上下滚动效果的示例代码
- vue监听滚动事件实现滚动监听
- Vue.js实战之通过监听滚动事件实现动态锚点
- vue实现消息的无缝滚动效果的示例代码
您可能感兴趣的文章:
相关文章
Java两个List<T> 求交集,差集,并集,去重后的并集
目录操作的List<T>声明求交集 retainAll()求差集 removeAll()求并集 addAll()求去重后的并集 操作的List<T>声明 oldList List<String> oldLi2022-04-08SpringMVC中MultipartFile转File的两种方式
在spring上传文件中,一般都使用了MultipartFile来接收,但是有需要用到File的地方,这里只介绍两种转为File的方法,当然也有一些其他的方法2022-04-08springboot整合Dubbo与Feign的实现?(无注册中心)
目录一,SpringBoot 整合 Dubbo1.1 服务提供者1.1.1 核心依赖1.1.2 核心配置1.1.3 服务提供者代码结构 1.1.4 服务提供者暴露的API(DubboDem2022-04-08
最新评论