VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-offcanvas-usage-methods/

⇱ Bootstrap 5 Offcanvas Usage Methods - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Offcanvas Usage Methods

Last Updated : 31 Jul, 2024

Bootstrap 5 Offcanvas methods are used to control the visibility of the offcanvas element, manually. For example, they can be used to show, hide, or toggle the Offcanvas element manually.

Bootstrap 5 Offcanvas Usage Methods:

  • toggle: It is used to toggle an offcanvas element's visibility. 
  • show: It is used to manually show an offcanvas element.
  • hide: It is used to manually hide an offcanvas element.
  • getInstance: It is used to get the instance of an offcanvas element.
  • getOrCreateInstance: It is used to get the instance of an offcanvas element, if an offcanvas element existed, or create one if it wasn't initialized. 

Syntax:

offcanvas.offcanvas_method()

Example 1: In this example, we will use "show" and "hide" offcanvas methods to show and hide the offcanvas element manually, with the click of buttons.

Output:

Example 2: In this example, we will use the "toggle" Offcanvas method to toggle (show/hide) the offcanvas element's visibility, manually, with the click of buttons.

Output:

Reference: https://getbootstrap.com/docs/5.0/components/offcanvas/#methods

Comment

Explore