How to add a 2 second delay to the scrollbar.init after the #menu-toggle-close button is clicked?
$('#menu-toggle-open').click(function () {
scrollbar.destroy(document.body)
})
$('#menu-toggle-close').click(function () {
scrollbar = Scrollbar.init(document.body, { delegateTo: document, alwaysShowTracks: true, speed: 0.7, damping:0.1, });
scrollbar.addListener(ScrollTrigger.update);
ScrollTrigger.defaults({ scroller: document.body });
})});
You can use setTimeout for this purpose. the second argument takes the delay in milliseconds, in this case it will be 2000 for 2 seconds.
$('#menu-toggle-close').click(function () {
setTimeout(() => {
scrollbar = Scrollbar.init(document.body, { delegateTo: document, alwaysShowTracks: true, speed: 0.7, damping:0.1, });
scrollbar.addListener(ScrollTrigger.update);
ScrollTrigger.defaults({ scroller: document.body });
}, 2000)
})});