it's my first time experimenting with Locomotive-scroll and I'm experiencing a setback :
I am trying to use the call
event (using data-scroll-call="my-id"
) to pass an element's id in order to use locomotive-scroll's scrollTo
method to "snap" to said section.
But whenever the scrollTo
method is triggered, nothing happens and I can't scroll anymore.
Here is and example section :
<section
id="s1"
data-scroll
data-scroll-call="s1"
data-scroll-repeat
data-scroll-offset="40%, 40%"
>
Here is the JS that handles this call (triggeredSections
is a simple list of ids I use to prevent the call
event from calling the scrollTo
method when the section leaves the viewport) :
let triggeredSections = []
scroll.on('call', id => {
if (triggeredSections.includes(id)) {
triggeredSections = triggeredSections.filter(el => el !== id)
return
}
triggeredSections.push(id)
scroll.scrollTo(`#${id}`, {
duration: 200
})
})
And here is a Codepen that reproduces this behavior : The Codepen