adchsm / Slidebars

Slidebars is a jQuery Framework for Off-Canvas Menus and Sidebars into your website or web app.
http://www.adchsm.com/slidebars/
MIT License
1.5k stars 307 forks source link

Clicking button (that opens the slidemenu) twice results in the menu not opening properly on following clicks #64

Closed janimattiellonen closed 10 years ago

janimattiellonen commented 10 years ago

Hi,

if I click on the button to open the menu and click it again, then clicking the button a third time won't open the menu anymore. If I continue clicking on the button, the menu is opened for a while and closed automatically - with jerkish movements.

The problem seems to go away if I in click somewhere else in the browser and then again on the button.

Code that I use:

$('.my-button').on('click', function() { mySlidebars.open('left'); });

adchsm commented 10 years ago

Hey Janimatti,

You may need to catch the click events and stop them from propagating or performing default behaviour. Try this:

$('.my-button').on('click', function(event) {
    event.stopPropagation();
    event.preventDefault();
    mySlidebars.open('left');
});

Let me know if that helps!

Thanks, Adam

janimattiellonen commented 10 years ago

Hi,

I tried your code now. It works better. Actually the button should no be named "Open menu". Instead it should probably act more like a toggle that can be used for showing and hiding the menu.

Unfortunately your code does not hide the menu if clicked again. Are there methods for programmatically closing the menu and checking if the menu is already open? I could use those.

Altrnatively there could be some kind of toggle feature built-in.

adchsm commented 10 years ago

Hey,

Great to hear that worked. Yes, there is a toggle you can use like:

$('.my-button').on('click', function(event) {
    event.stopPropagation();
    event.preventDefault();
    mySlidebars.toggle('left');
});

All of the API uses can be found at http://plugins.adchsm.me/slidebars/usage.php#api

I hope that helps,

Thanks, Adam

janimattiellonen commented 10 years ago

Thanks, works like a charm!

adchsm commented 10 years ago

Excellent, glad to hear you've got it going!