当前位置: 首页 > news >正文

前端滚动组件分享

分享一个前端可视化常用的卡片列表滚动组件,常用于可视化项目左右两侧的卡片列表的滚动。效果如下图所示:

在这里插入图片描述

组件描述
  1. 当鼠标移入滚动区域时,滚动行为停止当鼠标再次离开时,滚动继续
源码展示
<template><div ref="moocBox" class="custom-scroll-content" @mouseout="mouseOut" @mouseover="mouseOver"><slot></slot></div>
</template>
<script>
export default {name: 'CustomScroll',data() {return {speed: 50,myScroll: null};},created() {},mounted() {this.myScroll = setInterval(() => {this.scrollUp();}, this.speed);},destroyed() {clearInterval(this.myScroll);//  removeEventListener("scroll", this.myScroll);},beforeDestoryed() {clearInterval(this.myScroll);this.myScroll = null},methods: {/*** @description: 滚动* @return void 滚动*/scrollUp() {this.$refs.moocBox.scrollTop += 1;// 判断滚动条是否到底if (this.$refs.moocBox.scrollTop + this.$refs.moocBox.clientHeight >= this.$refs.moocBox.scrollHeight) {this.$refs.moocBox.scrollTop = 0;}},/*** @description: 鼠标滑过暂停滚动* @return void 清除定时器,实现暂停*/mouseOver() {clearInterval(this.myScroll);},/*** @description: 鼠标移开重新滚动* @return void 设定定时器,实现滚动*/mouseOut() {this.myScroll = setInterval(() => {this.scrollUp();}, this.speed);},}
};
</script>
<style>
.custom-scroll-content {height: 100%;overflow: auto;
}
</style>
使用指南
<template><div class="home"><div class="container__div_height-500"><CustomScroll><div class="item__div_height-100" v-for="i in 10" :key="i">{{ i+1 }}</div></CustomScroll></div></div>
</template>
import CustomScroll from '../components/customScroll.vue';export default {name: 'Home',components: {CustomScroll,},
}
</script>
<style>
.home {height: 100%;width: 100%;display: flex;align-items: center;justify-content: center;
}
.container__div_height-500 {height: 500px;width: 400px;
}
.item__div_height-100 {height: 100px;width: 100%;background-color: pink;margin-bottom: 12px;cursor: pointer;
}
.item__div_height-100:last-child {margin-bottom: 0;
}
::-webkit-scrollbar {width: 0!important;
}
</style>
属性说明
属性属性值类型
speed设置滚动速度,默认50Number
http://www.lryc.cn/news/297255.html

相关文章:

  • 【linux开发工具】vim详解
  • Compose | UI组件(十四) | Navigation-Data - 页面导航传递数据
  • 部署一个在线OCR工具
  • 【北邮鲁鹏老师计算机视觉课程笔记】01 introduction
  • maven依赖报错处理(或者maven怎么刷新都下载不了依赖)
  • [VulnHub靶机渗透] dpwwn: 1
  • Android14音频进阶:MediaPlayerService如何启动AudioTrack 下篇(五十六)
  • Python基础篇_修饰符(Decorators)【下】
  • C#,十进制展开数(Decimal Expansion Number)的算法与源代码
  • Vue3快速上手(一)使用vite创建项目
  • 使用navicat导出mysql离线数据后,再导入doris的方案
  • re:从0开始的CSS学习之路 1. CSS语法规则
  • npm install express -g报错或一直卡着,亲测可解决
  • 机器学习11-前馈神经网络识别手写数字1.0
  • vscode wsl远程连接 权限问题
  • VED-eBPF:一款基于eBPF的内核利用和Rootkit检测工具
  • 配置ARM交叉编译工具的通用步骤
  • 相机图像质量研究(5)常见问题总结:光学结构对成像的影响--景深
  • 使用django构建一个多级评论功能
  • 测试管理_利用python连接禅道数据库并自动统计bug数据到钉钉群
  • Python 小白的 Leetcode Daily Challenge 刷题计划 - 20240209(除夕)
  • BFS——双向广搜+A—star
  • LLM之LangChain(七)| 使用LangChain,LangSmith实现Prompt工程ToT
  • 新零售的升维体验,摸索华为云GaussDB如何实现数据赋能
  • vscode +git +gitee 文件管理
  • 【力扣】用栈判断有效的括号
  • 【目录】CSAPP的实验简介与解法总结(已包含Attack/Link/Architecture/Cache)
  • 【机器学习】数据清洗之识别缺失点
  • 【Vue】Vue基础入门
  • 正点原子-STM32通用定时器学习笔记(1)