vmitsaras / js-offcanvas

A lightweight, flexible jQuery off-canvas navigation plugin which lets you create fully accessible sidebar or top/bottom sliding (or push) panels with keyboard interactions and ARIA attributes.
http://codepen.io/vmitsaras/pen/gwGwJE
MIT License
270 stars 30 forks source link

Offcanvas without triggerButton #40

Closed n3t closed 5 years ago

n3t commented 5 years ago

Hi,

when creating offcanvas without triggerButton specified, an error 'Element required to initialize object' is raised.

    jQuery(function($) {
      $('#offcanvas').offcanvas({
        modifiers: 'left,overlay',
      });
    });

I use this code, as offcanvas in my case is not triggered by any alement, but appears as feedback to AJAX action (after user add something to cart).

I can bypass this issue by creating invisible element like this

    jQuery(function($) {
      $('#offcanvas').offcanvas({
        modifiers: 'left,overlay',
        triggerButton: jQuery('<span/>')
      });
    });

Is this expected behavior, or an issue? Would be nice to have option to omit triggerButton, when not needed.

thanks

Pavel

vmitsaras commented 5 years ago

Hi Pavel, thanks for that. I already thought of that, but unfortunately the triggerButton is required. I'll check it out and get back.

Did you try to use the Cart-Button as triggerButton instead?

n3t commented 5 years ago

Hi,

the point is, that there is no Cart button opening offcanvas. The cart button redirects user to cart already, offcanvas is displayed just after he adds something to cart from AJAX event only. So no control to display offcanvas manually by user...

Pavel

vmitsaras commented 5 years ago

Hi Pavel,

can you test it if this works and let me know https://github.com/vmitsaras/js-offcanvas/blob/40-offcanvas-without-triggerbutton/dist/_js/js-offcanvas.pkgd.js Thanks

n3t commented 5 years ago

Hi,

sorry for late reply, I was quite busy last few days. Yes, this works like a charm, thank you very much.

Pavel