i'm making a website where if you land on a particular div, the scrolling behaviour iterates through menu items. But I don't want the scrolling to actually happen. The current code is based on the scrolling distance travelled, but can I still use this property or any similar feature while disabling scrolling?
ScrollTrigger.create({
trigger: '#wrapper',
start: 'top top',
end: 'bottom bottom',
// scrub: true,
onUpdate: (self) => {
// Calculate the current scroll distance
const currentScrollDistance = self.scroll();
// Calculate the current menu index based on the scroll distance
let newMenuItemIndex = Math.floor(currentScrollDistance / scrollDistance);
newMenuItemIndex = clamp(newMenuItemIndex, 0, menuItems.length-1)
if (newMenuItemIndex !== currentMenuItemIndex) {
// REMOVE PREVIOUS PROPERTIES
menuItems[currentMenuItemIndex].classList.remove('selected');
let circlesPrv = contents[currentMenuItemIndex].querySelectorAll(".tags");
circlesPrv.forEach(circle=>{
circle.classList.remove('circle');
})
// ADD NEW PROPERTIES
menuItems[newMenuItemIndex].classList.add('selected');
let circlesCur = contents[newMenuItemIndex].querySelectorAll(".tags");
circlesCur.forEach(circle=>{
circle.classList.add('circle');
})
// UPDATE INDEX
currentMenuItemIndex = newMenuItemIndex;
}
}
}
You can use event.preventDefault
to stop the native behavior of any event and execute your functionality instead.