![]() |
VOOZH | about |
Bootstrap 5 Scrollspy dispose() method is used to remove the ScrollSpy functionality from an element. To use the dispose() method, you will need to select the element that the scrollspy is applied to and call the method on it. For example, if you have applied the scrollspy to a navbar with an ID of "navbar", you can call the dispose() method as follows.
Syntax:
$('#navbar').scrollspy('dispose');The dispose() method can be called at any time, even if the Scrollspy is not currently active. If you want to re-enable the Scrollspy after calling the dispose() method, you can simply call the Scrollspy function again with the same configuration as before.
Example 1: This code adds two buttons to the page, one to disable the scrollspy and another to enable it. The disable button has an event listener attached to it that is triggered when the button is clicked. The event listener calls the dispose() method of the scrollspy on the body element, which disables the scrollspy.
Output:
Example 2: This code adds a button to the page with the ID "disable-btn" with class btn btn-primary. The script adds an event listener to the button that is triggered when the button is clicked. The event listener calls the dispose() method of the scrollspy on the body element, which disables the scrollspy.
Output:
Reference:https://getbootstrap.com/docs/5.0/components/scrollspy/#dispose