Scroll Component
Component wrapper. Gathering all data-*
attributes from Locomotive Scroll element.
Must be rendered inside ScrollView.
Component props
Property name | Type | Reactive | Reference / Default value | Description |
---|---|---|---|---|
is | string | - | div | Specifies which HTML tag element to render. |
inViewClass | string | + | is-inview | Specifies which class to apply to an element when it is in view. |
position | string | + | data-scroll-position | ⬅️ |
offset | string | - | data-scroll-offset | ⬅️ |
repeat | boolean | - | data-scroll-repeat | ⬅️ |
speed | number | - | data-scroll-speed | ⬅️ |
cssProgress | boolean | + | data-scroll-css-progress | ⬅️ |
ignoreFold | boolean | + | data-scroll-ignore-fold | ⬅️ |
enableTouchSpeed | boolean | + | data-enable-touch-speed | ⬅️ |
Reactivity
If you are curious you can experiment and change properties directly on scrollElement.attributes
objects:
js
scrollElement.attributes.neededProperty = 'changed value'
scrollElement.attributes.neededProperty = 'changed value'
How to get access to scrollElement
you can see below in Expose section.
Events
Emit progress
and intersect
events. progress
event handler will take IProgressEventPayload
and intersect
event handler will take IIntersectEventPayload
.
See more types.ts
vue
<script setup lang="ts">
import { ScrollComponent } from "potiah";
import type { IProgressEventPayload, IIntersectEventPayload } from "potiah";
function handleProgress({ target, progress }: IProgressEventPayload) {
// some work...
}
function handleIntersect({ target, way, from }: IIntersectEventPayload) {
// and there
}
</script>
<template>
<ScrollComponent @progress="handleProgress" />
<ScrollComponent @intersect="handleIntersect" />
</template>
<script setup lang="ts">
import { ScrollComponent } from "potiah";
import type { IProgressEventPayload, IIntersectEventPayload } from "potiah";
function handleProgress({ target, progress }: IProgressEventPayload) {
// some work...
}
function handleIntersect({ target, way, from }: IIntersectEventPayload) {
// and there
}
</script>
<template>
<ScrollComponent @progress="handleProgress" />
<ScrollComponent @intersect="handleIntersect" />
</template>
Expose
All exposed properties available after component is ready. So you need to watch for ref.value?.scrollComponent
to make sure of that and then access properties on exposed object.
inView
- whether element in viewscreenel
- rendered HTML ElementscrollElement
- ScrollElement
Pass inView
to slot via v-slot
.
vue
<script setup lang="ts">
import { watch } from "vue";
import { ScrollComponent } from "potiah";
const comp = ref<InstanceType<typeof ScrollComponent>>()
watch(
() => comp.value?.scrollElement,
() => {
comp.value.inView
comp.value.el
comp.value.scrollElement
})
</script>
<template>
<ScrollComponent ref="comp" v-slot="{ inView }">
<!-- slot components -->
</ScrollComponent>
</template>
<script setup lang="ts">
import { watch } from "vue";
import { ScrollComponent } from "potiah";
const comp = ref<InstanceType<typeof ScrollComponent>>()
watch(
() => comp.value?.scrollElement,
() => {
comp.value.inView
comp.value.el
comp.value.scrollElement
})
</script>
<template>
<ScrollComponent ref="comp" v-slot="{ inView }">
<!-- slot components -->
</ScrollComponent>
</template>