el-scrollbar 动态更新内容 鼠标滚轮无效

embedded/2024/11/12 14:42:14/

有以下功能逻辑,实现了一个时间轴组件,点击+、-号后像地图那样放大组件以显示不同的UI。

默认显示年月:

当点击一下加号时切换为年: 

当点击减号时切换为日: 

即加号、减号点击就是在年月日显示进行切换。给Scrollview添加了鼠标滚动事件:当切换日期显示时滚轮滚动时,scrollview的滚动条没有反应,就很奇葩。。。

javascript">     <el-scrollbar  ref="scrollContainer" class="right-view" horizontal@wheel.native.prevent="handleScroll">

页面代码为:

javascript"><template><div class="flex-row container-view"><div class="left-view"><div class="placeholder-view"></div><div class="switch-view flex-column jc-between"><div class="h-view flex-row jc-around"><i class="btns-view flex-row el-icon-timer" style="justify-content: center;"@click="toCurrentAction"></i><i class="btns-view flex-row el-icon-circle-plus-outline" style="justify-content: center;"@click="toDayAction"></i><i class="btns-view flex-row el-icon-remove-outline" style="justify-content: center;"@click="toYearAction"></i></div><div class="flex-row w-100" style="height: 30px;"><div class="flex-column" style="width: 12px;"><div class="flex-column" style="height: 15px;justify-content:flex-end"><i style="width: 8px;height:8px;background-color:#a0a0a0;border-radius:4px"></i><i style="width: 1px;height:4px;background-color:#a0a0a0;"></i></div><div class="flex-column" style="height: 15px;justify-content:flex-start"><i style="width: 1px;height:4px;background-color:#a0a0a0;"></i><i style="width: 8px;height:8px;background-color:#a0a0a0;border-radius:4px"></i></div></div><div class="flex-column"><span class="flex-column"style="font-size:10px;color:#a0a0a0;height:15px;line-height:15px">自2021.01.01</span><span class="flex-column"style="font-size:10px;color:#a0a0a0;height:15px;line-height:15px">至2024.10.31</span></div></div></div></div><el-scrollbar  ref="scrollContainer" class="right-view" horizontal@wheel.native.prevent="handleScroll"><template v-if="viewMode == 1"><div class="date-view flex-column":style="{ width: (yearList.length / yearList.length * monthList.length * gutterGap) + 'px' }"><div class="flex-row w-100" style="height: 20px;"><p v-for="(item, index) in yearList" :key="index" style="color:#a0a0a0;font-size:13px;":style="{ width: (monthList.length / yearList.length * gutterGap) + 'px' }">{{ item.date }}</p></div><div class="flex-row" style="height: 20px;"><p v-for="item in monthList" :style="{ width: `${gutterGap}px` }"style="color:#505050;font-size:13px;">{{ item.month +'月' }}</p></div></div><div class="switch-view bd-blue":style="{ width: (yearList.length / yearList.length * monthList.length * gutterGap) + 'px' }"><div class="flex-row h-100" style="position: relative;"><p class="sep-h-line" v-for="(item, kdex) in monthList":style="{ left: (kdex * gutterGap + 10) + 'px' }"></p></div></div></template><template v-else-if="viewMode == 2"><div class="date-view flex-column":style="{ width: (yearList.length / yearList.length * monthList.length * gutterGap) + 'px' }"><div class="flex-row w-100" style="height: 20px;"><p v-for="(item, index) in yearList" :key="index" style="color:#a0a0a0;font-size:13px;":style="{ width: (monthList.length / yearList.length * gutterGap) + 'px' }">{{ item.date }}</p></div><div class="flex-row" style="height: 30px;"><div v-for="(item, mdex) in monthList" class="flex-column" :key="mdex"><span :style="{ width: `${gutterGap}px` }" style="color:#505050;font-size:13px;">{{item.month+ '月' }}</span><div class="flex-row"><span style="font-size: 12px;color:#505050;text-align:center;"v-for="(dtem, ddex) in daysList(item)" :key=ddex:style="{ width: `${gutterGap / monthDays(item)}px` }">{{ dtem.label }}</span></div></div></div></div><div class="switch-view bd-blue":style="{ width: (yearList.length / yearList.length * monthList.length * gutterGap) + 'px' }"><div class="flex-row h-100" style="position: relative;"><p class="sep-h-line" v-for="(item, kdex) in monthList":style="{ left: (kdex * gutterGap + 10) + 'px' }"></p></div></div></template><template v-else><div class="date-view flex-column" style="justify-content:flex-end":style="{ width: (yearList.length / yearList.length * monthList.length * gutterGap) + 'px' }"><div class="flex-row w-100" style="height: 20px;"><p v-for="(item, index) in yearList" :key="index" style="color:#a0a0a0;font-size:13px;":style="{ width: (monthList.length / yearList.length * gutterGap) + 'px' }">{{ item.date }}</p></div></div><div class="switch-view bd-blue":style="{ width: (yearList.length / yearList.length * monthList.length * gutterGap) + 'px' }"><div class="flex-row h-100" style="position: relative;"><p class="sep-h-line" v-for="(item, kdex) in monthList":style="{ left: (kdex * gutterGap + 10) + 'px' }"></p></div></div></template></el-scrollbar></div>
</template><script>
import { getDaysInMonth } from '@/utils/index.js'
export default {data() {return {gutterGap: 120,scrollWith: 0,//0年 1月 2日viewMode: 1,yearList: [{date: '2021'}, {date: '2022'}, {date: '2023'}, {date: '2024'}],monthList: [],dayList: [{ "day": '1' }, { "day": '2' }, { "day": '3' }, { "day": '4' }]}},created() {this.autoMonths()this.$nextTick(() => {let atarget = document.querySelector(".right-view")this.scrollWith = atarget.offsetWidth})},computed: {scrollWrapper() {return this.$refs.scrollContainer.$refs.wrap}},mounted() {this.$nextTick(() => {this.$refs.scrollContainer.update()})},methods: {autoMonths() {this.monthList.removeAllObject()this.yearList.forEach((e, index) => {for (let a = 0; a < 12; a++) {let d = e.date + '-' + (a < 10 ? '0' : '') + (a + 1)let k = {month: a + 1,date: d}this.monthList.push(k)}})},handleScroll(e) {const eventDelta = e.wheelDelta || -e.deltaY * 40const $scrollWrapper = this.scrollWrapperlet scrolled = $scrollWrapper.scrollLeft + eventDelta / 4$scrollWrapper.scrollLeft = scrolledthis.$emit("scrolled", scrolled)},toCurrentAction() { },toDayAction() {this.viewMode = Math.max(0, this.viewMode - 1)if (this.viewMode == 1) {//显示月this.gutterGap = 120}else {//显示年this.gutterGap = 30}let vl = Math.max(this.scrollWith / (this.yearList.length * 12), this.gutterGap)vl = Math.ceil(vl)this.gutterGap = vlthis.$nextTick(() => {this.$refs.scrollContainer.update();});},toYearAction() {//单位年this.viewMode = Math.min(2, this.viewMode + 1)if (this.viewMode == 1) {//显示月this.gutterGap = 120}else {//显示日this.gutterGap = 720}this.$nextTick(() => {this.$refs.scrollContainer.update();});},monthDays(m) {let c = getDaysInMonth(m.date)return c},daysList(m) {let c = getDaysInMonth(m.date)let list = []for (let i = 0; i < c; i++) {let e = {label: (i + 1) + '',value: m.date + (i < 10 ? '0' : '') + (i + 1)}list.push(e)}return list}}
}
</script><style lang="scss" scoped>
.flex-row {display: flex;flex-direction: row;justify-content: flex-start;align-items: center;
}.flex-column {display: flex;flex-direction: column;justify-content: flex-start;align-items: center;
}.container-view {min-height: 150px;height: 150px;max-height: 150px;
}.left-view {width: 100px;display: flex;flex-direction: column;justify-content: space-between;align-items: flex-start;
}.jc-around {justify-content: space-around;
}.jc-between {justify-content: space-between;
}.right-view {width: calc(100% - 100px);background-color: transparent;
}.date-view {width: 100%;height: 50px;
}.placeholder-view {height: 50px;background-color: transparent;
}.switch-view {background-color: #f3f5f9;height: 100px;
}.h-view {background-color: white;margin: 5px;
}.btns-view {width: 24px;height: 24px;background-color: transparent;
}.bd-blue {border-top: 20px solid #0286ef;
}.sep-h-line {position: absolute;width: 1px;height: 100%;background-color: #e2e7fb;
}::v-deep {.is-horizontal {height: 10px !important;left: 0px;display: inline !important;margin-top: 6px;}
}
</style>

因scrollview内的内容不断的进行变化,他的contentsize也是动态变化,但此时当切换后鼠标滚轮无法触发Scrollview的滚动条一块儿跟着滑动。

修正方案为:强行更新scrollview,出现的问题随之修复。

javascript">this.$nextTick(() => {this.$refs.scrollContainer.update();
});

http://www.ppmy.cn/embedded/136438.html

相关文章

Java并发无锁篇--乐观锁(非阻塞)

共享模型之无锁 问题提出 package com.zjy.unlock;import java.util.ArrayList; import java.util.List;public class AccountDemo {public static void main(String[] args) {Account account new AccountUnsafe(10000);Account.demo(account);} }class AccountUnsafe impl…

java.lang.NoClassDefFoundError: org/springframework/aot/AotDetector问题解决

原因&#xff1a;mybatis版本问题 由于项目需要部署服务器上&#xff0c;需要将一系列依赖进行升级 到mybatis时&#xff0c;会出现这个问题 参考mybatis-spring官网可以看到mybatis-spring mybatis、mybatis-spring、spring依赖和jdk版本不对应&#xff0c;因此爆错 解决方法&…

ML 系列:机器学习和深度学习的深层次总结( 20)— 离散概率分布 (Bernoulli 分布)

一、说明 离散概率分布&#xff0c;最早的杰出任务是贝努力&#xff0c;而贝努力分布是最早的离散概率模型&#xff0c;至今依然是重要的概率理论&#xff0c;在物理学的热力学、量子理论均有巨大意义。 雅各布伯努利 &#xff08;Jacob Bernoulli&#xff09; 是一位杰出的数学…

编写虚拟的GPIO控制器的驱动程序:和pinctrl的交互使用

往期内容 本专栏往期内容&#xff1a; Pinctrl子系统和其主要结构体引入Pinctrl子系统pinctrl_desc结构体进一步介绍Pinctrl子系统中client端设备树相关数据结构介绍和解析inctrl子系统中Pincontroller构造过程驱动分析&#xff1a;imx_pinctrl_soc_info结构体Pinctrl子系统中c…

CycleGAN算法简述

1. 简介 CycleGAN是一种图像到图像的翻译模型&#xff0c;旨在无配对训练数据的情况下完成跨域图像转换。传统方法需要成对的输入-输出数据&#xff0c;但这种配对数据的获取往往代价高昂且难以实现。CycleGAN通过使用无配对数据的训练策略&#xff0c;实现从一个图像域到另一…

(十三)JavaWeb后端开发——MySQL2

目录 1.DQL数据查询语言 1.1基本查询 1.2条件查询 where关键字 1.3分组查询 1.4排序查询 1.5分页查询 2.多表设计 3.多表查询——联查 4.多表查询——子查询​ 5.MySQL 事务 6.事务管理&#xff08;事务进阶&#xff09; 7.MySQL 索引 1.DQL数据查询语言 分为五大…

这是一个bug求助帖子--安装kali 遇坑

第一个报错 介质&#xff1a;kali-linux-2024.1-live-amd64 环境&#xff1a;Dell笔记本 i510代cpu 现象及操作 安装完以后 然后我换了个国内的源进行了以下操作 apt-get update&#xff1a;更新源列表 apt-get upgrade&#xff1a;更新所有可以更新的软件包 然后进行清理。…

数据结构:时间复杂度空间复杂度

专栏说明&#xff1a;本专栏用于数据结构复习&#xff0c;文章中出现的代码由C语言实现&#xff0c;在专栏中会涉及到部分OJ题目&#xff0c;如对你学习有所帮助&#xff0c;可以点赞鼓励一下博主喔&#x1f493; 博客主页&#xff1a;Duck Bro 博客主页系列专栏&#xff1a;数…