0

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 });
})});
gjjr
  • 607
  • 5
  • 13

1 Answers1

1

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)
    })});
Khalil
  • 1,495
  • 6
  • 14