-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(components): [scrollbar] multiple rendering (#15822)
* fix:The namespace of the showOverflowTooltip is invalid. * fix(components): [scrollbar] multiple rendering * fix(components): [scrollbar] multiple rendering * fix(components): [scrollbar] multiple rendering * Update packages/components/scrollbar/src/bar.vue Co-authored-by: kooriookami <38392315+kooriookami@users.noreply.github.com> * test(components): [scrollbar] adjusting style attributes --------- Co-authored-by: kooriookami <38392315+kooriookami@users.noreply.github.com>
- Loading branch information
1 parent
f33979d
commit 5e3fa20
Showing
4 changed files
with
52 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,67 @@ | ||
<template> | ||
<thumb :move="moveX" :ratio="ratioX" :size="width" :always="always" /> | ||
<thumb :move="moveX" :ratio="ratioX" :size="sizeWidth" :always="always" /> | ||
<thumb | ||
:move="moveY" | ||
:ratio="ratioY" | ||
:size="height" | ||
:size="sizeHeight" | ||
vertical | ||
:always="always" | ||
/> | ||
</template> | ||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import { inject, ref } from 'vue' | ||
import { GAP } from './util' | ||
import Thumb from './thumb.vue' | ||
import { barProps } from './bar' | ||
import { scrollbarContextKey } from './constants' | ||
const props = defineProps(barProps) | ||
const scrollbar = inject(scrollbarContextKey) | ||
const moveX = ref(0) | ||
const moveY = ref(0) | ||
const sizeWidth = ref('') | ||
const sizeHeight = ref('') | ||
const ratioY = ref(1) | ||
const ratioX = ref(1) | ||
const handleScroll = (wrap: HTMLDivElement) => { | ||
if (wrap) { | ||
const offsetHeight = wrap.offsetHeight - GAP | ||
const offsetWidth = wrap.offsetWidth - GAP | ||
moveY.value = ((wrap.scrollTop * 100) / offsetHeight) * props.ratioY | ||
moveX.value = ((wrap.scrollLeft * 100) / offsetWidth) * props.ratioX | ||
moveY.value = ((wrap.scrollTop * 100) / offsetHeight) * ratioY.value | ||
moveX.value = ((wrap.scrollLeft * 100) / offsetWidth) * ratioX.value | ||
} | ||
} | ||
const update = () => { | ||
const wrap = scrollbar?.wrapElement | ||
if (!wrap) return | ||
const offsetHeight = wrap.offsetHeight - GAP | ||
const offsetWidth = wrap.offsetWidth - GAP | ||
const originalHeight = offsetHeight ** 2 / wrap.scrollHeight | ||
const originalWidth = offsetWidth ** 2 / wrap.scrollWidth | ||
const height = Math.max(originalHeight, props.minSize) | ||
const width = Math.max(originalWidth, props.minSize) | ||
ratioY.value = | ||
originalHeight / | ||
(offsetHeight - originalHeight) / | ||
(height / (offsetHeight - height)) | ||
ratioX.value = | ||
originalWidth / | ||
(offsetWidth - originalWidth) / | ||
(width / (offsetWidth - width)) | ||
sizeHeight.value = height + GAP < offsetHeight ? `${height}px` : '' | ||
sizeWidth.value = width + GAP < offsetWidth ? `${width}px` : '' | ||
} | ||
defineExpose({ | ||
handleScroll, | ||
update, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters