vue 消息左右滚动(前后无缝衔接)

2024-03-23 05:20

本文主要是介绍vue 消息左右滚动(前后无缝衔接),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

演示效果

封装的组件

<!--* @Author:* @Date: 2024-03-21 19:21:58* @LastEditTime: 2024-03-21 20:31:50* @LastEditors: Please set LastEditors* @Description: 消息左右滚动
-->
<template><divid="textScroll"class="text-scroll"@mousemove="inBox"@mouseleave="leaveBox"><divv-for="i in 2":id="'scrollItem' + i":key="'scrollItem' + i"class="scroll-item":style="{ display: i === 1 ? 'flex' : 'none' }"><slot></slot></div></div>
</template><script>
export default {components: {},data() {return {left: 0,textScrollDiv: null,timer: null,scrollItemWidth: 0,isScroll: false};},computed: {},destroyed() {clearInterval(this.timer);},mounted() {const that = this;this.$nextTick(() => {that.textScrollDiv = document.querySelector('#textScroll');that.scrollItemWidth = document.querySelector('#scrollItem1').clientWidth;const outerBoxWidth = that.textScrollDiv.clientWidth;if (outerBoxWidth < that.scrollItemWidth) {this.isScroll = true;that.textScrollDiv.style.width = `${that.scrollItemWidth * 2}px`;that.timer = setInterval(function() {that.moveLeft();}, 30);document.querySelector('#scrollItem2').style.display = 'flex';}});},methods: {moveLeft() {if (this.textScrollDiv) {this.left -= 1;if (Math.abs(this.left) > this.scrollItemWidth) {this.left = 0;}this.textScrollDiv.style.transform = `translate(${this.left}px, 0px)`;}},// 鼠标划入区域inBox() {if (this.isScroll) {clearInterval(this.timer);this.timer = null;}},// 鼠标离开区域leaveBox() {if (this.isScroll) {const that = this;this.timer = setInterval(function() {that.moveLeft();}, 30);}}}
};
</script>
<style lang="less" scoped>
.text-scroll {display: flex;flex-wrap: nowrap;transition: all 0ms ease-in 0s;.scroll-item {display: flex;flex-wrap: nowrap;}
}
</style>

外部引用

<template><!-- 公告信息板块 --><div v-if="noticeInfo && noticeInfo.length > 0" class="notice-plate"><div class="plate-body"><div class="plate-icon"><i class="sxqyjj-iconfont sxqyjj-xiaoxi1"></i></div><div class="plate-info" @click="handleInfo($event)"><textScroll><divv-for="(item, i) in noticeInfo":key="'notice' + i"class="info-item":data-my-id="item.id">{{ item.title }}<div v-if="i < noticeInfo.length - 1" class="line-split"></div></div></textScroll></div><div class="plate-more" @click="moreInfo">更多<i class="sxqyjj-iconfont sxqyjj-chevron-right"></i></div></div></div>
</template>
<script>
import textScroll from '@packages/views/components/text-scroll/index.vue';export default {name: 'Index',components: {textScroll},data() {return {noticeInfo: [],};},created() {this.getLastThreeConsultation();},methods: {// 获取重点资讯getLastThreeConsultation() {this.$api['search/getLastThreeConsultation']().then(res => {if (res.code === this.$constant.apiServeCode.SUCCESS_CODE) {this.noticeInfo = res.data || [];}return true;}).catch(err => {console.log(err);});}}}
};
</script>
<style lang="less" scoped>
/* stylelint-disable */.notice-plate {width: 1328px;margin: 0 auto;margin-top: 24px;.plate-body {display: flex;align-items: flex-start;width: 100%;height: 48px;padding: 10px 16px;margin-left: -64px;background: white;border: 1px solid rgba(0, 0, 0, 0.1);border-radius: 4px 4px 4px 4px;.plate-icon {width: 28px;height: 28px;margin-right: 16px;line-height: 28px;color: rgba(255, 143, 31, 1);text-align: center;background: rgb(255, 247, 241);border-radius: 4px 4px 4px 4px;}.plate-info {width: calc(100% - 112px);height: 28px;overflow: hidden;line-height: 28px;.info-item {position: relative;margin-right: 32px;font-weight: 500;white-space: nowrap;&:hover {color: rgba(0, 128, 255, 1);cursor: pointer;}}.line-split {position: absolute;top: 6px;right: -16px;width: 2px;height: 12px;border-right: 1px solid rgba(217, 217, 217, 1);}}.plate-more {height: 28px;margin-left: 16px;font-size: 14px;line-height: 28px;color: @text-2;cursor: pointer;i {margin-left: 4px;}}}
}
</style>

这篇关于vue 消息左右滚动(前后无缝衔接)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/837269

相关文章

Redis消息队列实现异步秒杀功能

《Redis消息队列实现异步秒杀功能》在高并发场景下,为了提高秒杀业务的性能,可将部分工作交给Redis处理,并通过异步方式执行,Redis提供了多种数据结构来实现消息队列,总结三种,本文详细介绍Re... 目录1 Redis消息队列1.1 List 结构1.2 Pub/Sub 模式1.3 Stream 结

HTML5中的Microdata与历史记录管理详解

《HTML5中的Microdata与历史记录管理详解》Microdata作为HTML5新增的一个特性,它允许开发者在HTML文档中添加更多的语义信息,以便于搜索引擎和浏览器更好地理解页面内容,本文将探... 目录html5中的Mijscrodata与历史记录管理背景简介html5中的Microdata使用M

html5的响应式布局的方法示例详解

《html5的响应式布局的方法示例详解》:本文主要介绍了HTML5中使用媒体查询和Flexbox进行响应式布局的方法,简要介绍了CSSGrid布局的基础知识和如何实现自动换行的网格布局,详细内容请阅读本文,希望能对你有所帮助... 一 使用媒体查询响应式布局        使用的参数@media这是常用的

HTML5表格语法格式详解

《HTML5表格语法格式详解》在HTML语法中,表格主要通过table、tr和td3个标签构成,本文通过实例代码讲解HTML5表格语法格式,感兴趣的朋友一起看看吧... 目录一、表格1.表格语法格式2.表格属性 3.例子二、不规则表格1.跨行2.跨列3.例子一、表格在html语法中,表格主要通过< tab

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

前端下载文件时如何后端返回的文件流一些常见方法

《前端下载文件时如何后端返回的文件流一些常见方法》:本文主要介绍前端下载文件时如何后端返回的文件流一些常见方法,包括使用Blob和URL.createObjectURL创建下载链接,以及处理带有C... 目录1. 使用 Blob 和 URL.createObjectURL 创建下载链接例子:使用 Blob

Vuex Actions多参数传递的解决方案

《VuexActions多参数传递的解决方案》在Vuex中,actions的设计默认只支持单个参数传递,这有时会限制我们的使用场景,下面我将详细介绍几种处理多参数传递的解决方案,从基础到高级,... 目录一、对象封装法(推荐)二、参数解构法三、柯里化函数法四、Payload 工厂函数五、TypeScript

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me