![]() |
VOOZH | about |
An Offcanvas can be triggered or used using two ways using data attributes and using JavaScript. The data-attributes approach needs two attributes. These data attributes are added to the anchor link or button which is used to trigger the off-canvas. Offcanvas class is added to the div which is the off-canvas. container.
Bootstrap 5 Offcanvas Usage Data Attributes:
Syntax:
<button class="btn" type="button" data-bs-toggle="offcanvas" data-bs-target="id">... </button> <div class="offcanvas" id="..."> ... </div>
Example 1: The example below demonstrates how we can trigger the offcanvas using the data-attributes.
Output:
Example 2: The example below demonstrates how we can trigger the offcanvas using the data-attributes in the button which triggers a top off-canvas using the offcanvas-top.
Output:
Reference: https://getbootstrap.com/docs/5.0/components/offcanvas/#via-data-attributes