Scroll View
Main component.
Layout change
Due to LocomotiveScroll implementation it is not possible to change layout.
To prevent unexpected behaviour do not use conditional rendering (v-if
) or change layout (v-show
) inside view on components/elements that have width/height, change these properties dynamically (after rendering) of elements within ScrollView
IF there is ScrollComponent
s.
Solution depends on the bravery of LocomotiveScroll team and may come later, thanks them for their work!
Props
Property name | Type | Reactive | Default value | Description |
---|---|---|---|---|
root | boolean | - | false | Specifies when the component will wrap and listen to the scroll event on the entire document or create wrapper & content elements. |
cssProgress | boolean | + | false | Specifies whether or not to display the progress value on the root element in the --view-progress CSS custom property (variable). Possible values are 0 to 1. |
cssDirection | boolean | + | false | Same as cssProgress ⬆️, but in --scroll-direction property. Possible values are -1 (up), 1 (down). |
wrapperIs | string | - | div | Specifies which HTML tag element to render. |
contentIs | string | - | div | ⬆️ |
horizontal | boolean | - | false | Scroll orientation. Default - vertical |
duration | number | + | 1 | Scroll duration. See more here |
Other props are options from Lenis, options from LocomotiveScroll.
Non-reactive
All other props are non-reactive. If you are curious you can experiment and change properties directly on LocomotiveScroll.lenisOptions
and Lenis.options
objects:
potiah.scroll.lenisOptions.neededProperty = 'changed value'
potiah.scroll.lenisInstance.options.neededProperty = 'changed value'
potiah.scroll.lenisOptions.neededProperty = 'changed value'
potiah.scroll.lenisInstance.options.neededProperty = 'changed value'
Events
Emit lenis-scroll
event. Single argument passed to handler is Lenis.
<script setup lang="ts">
import type Lenis from '@studio-freight/lenis';
import { ScrollView } from "potiah";
function onLenisScroll({ progress, ...otherLenisProperties }: Lenis) {
// do what you want
}
</script>
<template>
<ScrollView @lenis-scroll="onLenisScroll">
<!-- content -->
</ScrollView>
</template>
<script setup lang="ts">
import type Lenis from '@studio-freight/lenis';
import { ScrollView } from "potiah";
function onLenisScroll({ progress, ...otherLenisProperties }: Lenis) {
// do what you want
}
</script>
<template>
<ScrollView @lenis-scroll="onLenisScroll">
<!-- content -->
</ScrollView>
</template>
Access to elements
If you need access to wrapper or/and content elements you can find it on Lenis
instance after scroll is ready.
<script setup lang="ts">
import { watch } from "vue";
import { usePotiah } from "potiah";
const { potiah } = usePotiah();
watch(() => potiah.scroll, (s) => {
if (s) {
potiah.scroll.lenisInstance.rootElement
// or
potiah.scroll.lenisInstance.options.wrapper
potiah.scroll.lenisInstance.options.content
}
}, { immediate: true })
</script>
<script setup lang="ts">
import { watch } from "vue";
import { usePotiah } from "potiah";
const { potiah } = usePotiah();
watch(() => potiah.scroll, (s) => {
if (s) {
potiah.scroll.lenisInstance.rootElement
// or
potiah.scroll.lenisInstance.options.wrapper
potiah.scroll.lenisInstance.options.content
}
}, { immediate: true })
</script>