Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/src/composables/useScrollPosition.js b/src/composables/useScrollPosition.js
index 1cf3373146..d32f6a261e 100644
--- a/src/composables/useScrollPosition.js
+++ b/src/composables/useScrollPosition.js
@@ -1,52 +1,49 @@
import { onMounted, onUnmounted, ref } from 'vue'
import { useWindowSize } from 'src/composables/useWindowSize.js'
export function useScrollPosition() {
const x = ref(0)
const y = ref(0)
const inProgress = ref(false)
const update = (e) => {
x.value = window.scrollX
y.value = window.scrollY
}
onMounted(() => {
window.addEventListener('scroll', update)
update()
})
onUnmounted(() => {
window.removeEventListener('scroll', update)
})
const scrollBy = async (x1, y1, options) => {
inProgress.value = true
await window.scrollBy(x1, y1, options)
inProgress.value = false
}
const scrollIntoView = async (element, options) => {
if (element == null) throw new TypeError(`Element is ${element}!`)
inProgress.value = true
- let call = element.scrollIntoViewIfNeeded
- if (!call) {
- call = (options) => {
- const { height: windowHeight } = useWindowSize()
- const { top, height } = element.getBoundingClientRect()
- const bottom = top + height
-
- const biggerThanScreen = height > windowHeight
- const aboveTop = top < 0
- const belowBottom = bottom > windowHeight.value
- if (aboveTop || belowBottom || biggerThanScreen) {
- element.scrollIntoView(options)
- }
+ if (!element.scrollIntoViewIfNeeded) {
+ const { height: windowHeight } = useWindowSize()
+ const { top, height } = element.getBoundingClientRect()
+ const bottom = top + height
+
+ const biggerThanScreen = height > windowHeight
+ const aboveTop = top < 0
+ const belowBottom = bottom > windowHeight.value
+ if (aboveTop || belowBottom || biggerThanScreen) {
+ await element.scrollIntoView(options)
}
}
- await call(options)
+ await element.scrollIntoViewIfNeeded(options)
inProgress.value = false
}
return { x, y, scrollBy, scrollIntoView, inProgress }
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Sep 19, 12:19 AM (14 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1763616
Default Alt Text
(2 KB)

Event Timeline