Documentation

Documentation - Offcanvas.

Discover Marssel: an intelligent, minimal configuration CSS framework designed for fast interfaces and a simplified developer experience.

Offcanvas

Marssel integrates an offcanvas system to create sliding side panels from the edges of the screen. Ideal for navigation menus, filters, shopping carts or any secondary content.

Basic setup

The OffcanvasManager is automatically initialized:

const marssel = new Marssel();
// The OffcanvasManager is ready to use

HTML structure

An offcanvas consists of a trigger and a panel:

Preview
<button data-offcanvas-target="offcanvas-menu">
    Open menu
</button>

<div id="offcanvas-menu" class="offcanvas offcanvas-start">
    <div class="offcanvas-header">
        <h5 class="offcanvas-title c-[black]">Menu</h5>
        <button class="offcanvas-close">&times;</button>
    </div>
    <div class="offcanvas-body">
        <p>Menu content</p>
    </div>
</div>

Positions available

Set the position with the appropriate classes:

<!-- From the left (default) -->
<div id="offcanvas-start" class="offcanvas offcanvas-start">
    <!-- Content -->
</div>

<!-- From the right -->
<div id="offcanvas-end" class="offcanvas offcanvas-end">
    <!-- Content -->
</div>

<!-- From the top -->
<div id="offcanvas-top" class="offcanvas offcanvas-top">
    <!-- Content -->
</div>

<!-- From the bottom -->
<div id="offcanvas-bottom" class="offcanvas offcanvas-bottom">
    <!-- Content -->
</div>

Scroll lock

Control page scrolling with data-offcanvas-lock-scroll:

<!-- With lock (default) -->
<button data-offcanvas-target="offcanvas-menu"
        data-offcanvas-lock-scroll="true">
    Open
</button>

<!-- Without locking -->
<button data-offcanvas-target="offcanvas-menu"
        data-offcanvas-lock-scroll="false">
    Open
</button>

JavaScript API

Control offcanvas programmatically:

// Show an offcanvas
marssel.offcanvasManager.show('offcanvas-id');

// Show without locking the scroll
marssel.offcanvasManager.show('offcanvas-id', false);

// Hide active offcanvas
marssel.offcanvasManager.hideActive();

// Create an offcanvas dynamically
marssel.offcanvasManager.create({
    id: 'new-offcanvas',
    title: 'Nouveau panneau',
    content: '<p>Contenu dynamique</p>',
    position: 'end' // 'start', 'end', 'top', 'bottom'
});

// Update content
marssel.offcanvasManager.update('offcanvas-id', {
    title: 'Nouveau titre',
    content: '<p>Nouveau contenu</p>'
});

// Delete an offcanvas
marssel.offcanvasManager.remove('offcanvas-id');

Custom Events

Listen to the opening and closing events:

// Opening event
document.getElementById('offcanvas-menu').addEventListener('offcanvas:shown', (e) => {
    console.log('Offcanvas ouvert');
    // Load data, etc.
});

// Closing event
document.getElementById('offcanvas-menu').addEventListener('offcanvas:hidden', (e) => {
    console.log('Offcanvas fermé');
    //Clean, save, etc.
});

Customizing styles

Style your offcanvas with Marssel classes:

<!-- Custom header -->
<div class="offcanvas-header---[bg-[gradient(135deg,_667eea_0%,_764ba2_100%)]+c-[ffffff]+border-[none]]">
    <h5 class="offcanvas-title---[font-size-[20px]+font-weight-[700]]">Title</h5>
    <button class="offcanvas-close---[c-[ffffff]+font-size-[28px]]">&times;</button>
</div>

<!-- Personalized bodysuit -->
<div class="offcanvas-body---[bg-[f8f9fa]+p-[24px]]">
    <p>Content</p>
</div>

Responsive offcanvas

Adapt the width according to the screen size:

<style>
.offcanvas-start,
.offcanvas-end {
    width: 300px;
}

@media (min-width: 768px) {
    .offcanvas-start,
    .offcanvas-end {
        width: 400px;
    }
}

@media (min-width: 1024px) {
    .offcanvas-start,
    .offcanvas-end {
        width: 500px;
    }
}
</style>

Complete example

The OffcanvasManager is automatically initialized:

Preview
<div id="complete-offcanvas" class="offcanvas offcanvas-end">

    
    <div class="offcanvas-header---[c-[ffffff]+border-[none]+p-[20px]] bg-linear-[90deg,rgba(2,0,36,1)_0%,rgba(9,9,121,1)_35%]">
        <h5 class="offcanvas-title---[font-size-[20px]+font-weight-[700]+m-[0]]">
            Custom sign
        </h5>
        <button class="offcanvas-close---[bg-[transparent]+border-[none]+c-[ffffff]+font-size-[28px]+cursor-[pointer]+opacity-[0.9]] offcanvas-close---[opacity-[1]]:hover">
            &times;
        </button>
    </div>

    
    <div class="offcanvas-body---[p-[20px]+bg-[f8f9fa]]">

        
        <div class="off-section---[mb-[24px]+p-[16px]+bg-[ffffff]+rounded-[8px]+shadow-[0_2px_4px_rgba(0,0,0,0.1)]]">
            <h6 class="mb-[12px] font-weight-[600] c-[1f2937]">Section 1</h6>
            <p class="m-[0]+c-[6b7280]">Description of the section</p>
        </div>

        
        <div class="off-section">
            <h6 class="mb-[12px] font-weight-[600] c-[1f2937]">Section 2</h6>
            <ul class="m-[0] p-[0] list-[none]">
                <li class="off-li---[mb-[8px]+d-[flex]+items-[center]+gap-[8px]]">
                    <span class="icon-[check] icon-size-[small] c-[10b981]"></span>
                    <span>Feature 1</span>
                </li>
                <li class="off-li">
                    <span class="icon-[check] icon-size-[small] c-[10b981]"></span>
                    <span>Feature 2</span>
                </li>
            </ul>
        </div>

        
        <div class="d-[flex]+gap-[12px]">
            <button class="btn-cancel-off---[flex-[1]+bg-[ffffff]+c-[374151]+p-[12px]+rounded-[6px]+border-[1px_solid_e5e7eb]+cursor-[pointer]] btn-cancel-off---[bg-[f9fafb]]:hover">
                Cancel
            </button>
            <button class="btn-validate-off---[flex-[1]+bg-[8b5cf6]+c-[ffffff]+p-[12px]+rounded-[6px]+border-[none]+cursor-[pointer]] btn-validate-off---[bg-[7c3aed]]:hover">
                To validate
            </button>
        </div>

    </div>

</div>
Menu

Menu content

Custom sign
Section 1

Description of the section

Section 2
  • Feature 1
  • Feature 2