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

列表自动向上滚动

列表自动向上滚动 鼠标放上去 自动停止滚动

  <div id="list-detail-main"><div class="my_table_thead_tr"><div v-for="(item, index) in header" :key="index" class="my_table_thead_th">{{ item }}</div></div><divref="contentScroll"class="my_table_tbody"@mousemove="move"@mouseleave="leave"@mousewheel="wheel"><div v-for="(item, ind) in dataset" :key="ind" class="my_table_tbody_tr"><divv-for="(value, index) in item":key="index"class="my_table_tbody_td":class="[{ is_special_col: index === 0 }]">{{ value }}</div></div></div></div>
</template><script setup lang="ts" name="SickDetailListDetailComponent">
import { ref, onBeforeUnmount, onUnmounted, watch } from 'vue';const props = defineProps({header: {type: Array,default: () => [],},dataset: {type: Array,default: () => [],},
});
// 定时器初始化
const timer = ref();
// content实例
const contentScroll = ref();watch(() => props.dataset,() => {if (props.dataset.length > 6) {start();}},{deep: true,},
);onBeforeUnmount(() => {// 清除定时器clearTimeout(timer.value);
});onUnmounted(() => {// 清除定时器clearTimeout(timer.value);
});/*** @Description: 鼠标移动事件* @Author: TQ*/
function move() {clearTimeout(timer.value);
}
/*** @Description: 鼠标离开事件* @Author: TQ*/
function leave() {if (props.dataset.length > 6) {start();}
}const wheel = (e) => {if (e.deltaY > 0) {contentScroll.value.scrollTop += 10;} else {contentScroll.value.scrollTop -= 10;}
};// 开启定时器方法
function start() {// 清除定时器clearTimeout(timer.value);// 定时器触发周期const speed = ref(75);timer.value = setInterval(scrollCore, speed.value);
}// 滚动事件核心
function scrollCore() {// 判断组件是否渲染完成// 如果列表数量过少不进行滚动if (contentScroll.value.childNodes.length < 6) {clearTimeout(timer.value);return;}// 组件进行滚动contentScroll.value.scrollTop += 1;// 判断滚动条是否滚动到底部if (contentScroll.value.scrollTop ===contentScroll.value.scrollHeight - contentScroll.value.clientHeight) {// 获取组件第一个节点const a = contentScroll.value.childNodes[0];// 删除节点contentScroll.value.removeChild(a);// 将该节点拼接到组件最后contentScroll.value.append(a);}
}
</script><style lang="scss" scoped>
.is_special_col {color: #c4c4c4 !important;text-align: left !important;
}#list-detail-main {padding-bottom: 20px;padding-left: 16px;pointer-events: auto;.my_table_thead_tr {display: flex;justify-content: space-between;width: 432px;padding: 0 8px;.my_table_thead_th {color: #356eff;}}.my_table_tbody {width: 432px;height: 220px;margin-top: 5px;overflow: hidden;.my_table_tbody_tr {display: flex;align-items: center;justify-content: space-between;height: 40px;padding: 0 8px;margin: 5px 0;background-color: #0f1726;border: 1px solid transparent;&:hover {border: 1px solid #d5f31d;}.my_table_tbody_td {font-size: 12px;color: #5fe3ff;text-align: center;&:first-child {width: 80px;}&:nth-child(2) {width: 64px;}&:nth-child(3) {width: 80px;}&:nth-child(4) {width: 64px;}&:last-child {width: 64px;}}}}
}
</style>
http://www.lryc.cn/news/209363.html

相关文章:

  • 嘴笨的技术人员怎么发言
  • vue源码分析(三)——new Vue 的过程(详解data定义值后如何获取的过程)
  • 软考系统架构师知识点集锦四:信息安全技术基础知识
  • Vscode中不显示.ipynb文件单元格行号
  • 【Oracle】[INS-30131]执行安装程序验证所需的初始设置失败。
  • 二进制部署kubernetes集群的推荐方式
  • 智能矩阵,引领商业新纪元!拓世方案:打破线上线下界限,开启无限营销可能!
  • ADB原理(第四篇:聊聊adb shell ps与adb shell ps有无双引号的区别)
  • 「网络编程」数据链路层协议_ 以太网协议学习
  • 通过python操作neo4j
  • Ubuntu中查看电脑有多少个核——lscpu
  • Python学习笔记第七十二天(Matplotlib imread)
  • 安卓核心板_天玑700、天玑720、天玑900_5G模块规格参数
  • CS224W2.2——传统基于特征的方法(边层级特征)
  • python—openpyxl操作excel详解
  • 汽车行驶性能的主观评价方法(2)-驾驶员的任务
  • server2012 通过防火墙开启局域网内限定IP进行远程桌面连接
  • lvs+keepalived: 高可用集群
  • C++标准模板(STL)- 类型支持 (类型特性,is_pointer,is_lvalue_reference,is_rvalue_reference)
  • C++——类和对象(上)
  • ffmpeg中examples编译报不兼容错误解决办法
  • Python与CAD系列基础篇(十一)图形旋转、镜像、缩放
  • STM32串口通信
  • Kafka笔记
  • 【1.2】神经网络:神经元与激活函数
  • 【PythonRS】Pyrsgis库安装+基础函数使用教程
  • 线扫相机DALSA--分频倍频计算公式及原理
  • 1818_ChibiOS的计数信号量
  • 企业微信接入芋道SpringBoot项目
  • 群晖上搭建teamspeak3语音服务器