Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playground/src/pages/controls/ScrollControlsDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const gl = {

useControls('fpsgraph')
useControls({
progress: progress.value,
progress,
})

const { onLoop } = useRenderLoop()
Expand Down
31 changes: 18 additions & 13 deletions src/core/controls/ScrollControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const { height, width } = useWindowSize()
let initCameraPos = 0
const initialized = ref(false)

const progress = ref(0)
const progressScroll = ref(0)
const scrollNodeY = ref(0)
const direction = props.horizontal ? 'x' : 'y'
Expand Down Expand Up @@ -112,21 +111,21 @@ watch(
},
)

watch(windowY, (value) => {
if (!isScrolling.value && !props.htmlScroll) return
function updateScroll(value: number) {
progressScroll.value = (value / height.value / (scrollNodeY.value / height.value - 1))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this working for horizontal axis??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

progress.value = -1 * progressScroll.value
emit('update:modelValue', progressScroll.value)
}

watch(windowY, (value) => {
if (!isScrolling.value && !props.htmlScroll) return
updateScroll(value)
})
watch(containerY, (value) => {
progressScroll.value = (value / height.value / (scrollNodeY.value / height.value))
progress.value = -1 * progressScroll.value
emit('update:modelValue', progressScroll.value)
updateScroll(value)

})
watch(containerX, (value) => {
progressScroll.value = (value / width.value / (scrollNodeY.value / width.value - 1))
progress.value = +progressScroll.value
emit('update:modelValue', progressScroll.value)
updateScroll(value)
})

watch(
Expand All @@ -143,6 +142,8 @@ watch(
canvas.style.left = '0'
}
scrollNodeY.value = document.body.scrollHeight
// Init scroll value
updateScroll(windowY.value)
}
else {
const fixed = document.createElement('div')
Expand Down Expand Up @@ -174,9 +175,13 @@ watch(
canvas.style.width = '100%'
}
scrollContainer.appendChild(fill)
value.domElement.parentNode.style.position = 'relative'
value?.domElement?.parentNode?.appendChild(scrollContainer)
if (value?.domElement?.parentNode) {
value.domElement.parentNode.style.position = 'relative'
value.domElement.parentNode.appendChild(scrollContainer)
}
scrollNodeY.value = props.horizontal ? width.value * props.pages : height.value * props.pages
// Init scroll value
updateScroll(props.horizontal ? containerX.value : containerY.value)
}
},
{
Expand All @@ -189,7 +194,7 @@ const { onLoop } = useRenderLoop()
onLoop(() => {
if (camera.value?.position) {
const delta
= (progress.value * props.distance - camera.value.position[direction] + initCameraPos) * props.smoothScroll
= (-progressScroll.value * props.distance - camera.value.position[direction] + initCameraPos) * props.smoothScroll

camera.value.position[direction] += delta
if (wrapperRef.value.children.length > 0) {
Expand Down