Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help: Toggle Class From Another Element? #13

Closed
unijez opened this issue Jul 5, 2018 · 6 comments
Closed

Help: Toggle Class From Another Element? #13

unijez opened this issue Jul 5, 2018 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@unijez
Copy link

unijez commented Jul 5, 2018

Is it possible to toggle a class from another element, for example a slide navigation panel controlled via burger button. Once open close from another div.

Currently i have 2 buttons, the first opens the panel, adding active class, the second appears within that panel to close it, both are below...

Open Panel...
<button type="button" class="site-header__mobile-button lines-nav main-btn " data-toggle-class data-toggle-escape data-toggle-target=" .whole-page, .navigation-panel_holder, .navigation-panel_main, body" title="Navigation">Open Menu</button>

Once open close panel...
<button type="button" class="navigation-panel_main-button main-btn " data-toggle-class data-toggle-escape data-toggle-target=" .whole-page, .navigation-panel_holder, .navigation-panel_main, body" title="Navigation">Close Menu</button>

Both these work fine, but would it be possible to add another class, i'e an overlay outside of the panel so when you click anywhere else it toggles the above?

So a div click toggle class the above, the i try and set this up it seems to do funny things.

@Twikito
Copy link
Owner

Twikito commented Jul 5, 2018

Thanks for your question.

Did you try adding data-toggle-outside attribute on your trigger button ?

By the way, if your close button is inside your navigation panel, you only need to add data-toggle-trigger-off attribute, nothing else.

Hope that will help you.

@Twikito Twikito added the help wanted Extra attention is needed label Jul 5, 2018
@unijez
Copy link
Author

unijez commented Jul 5, 2018

Thank you for the suggestion, the above buttons appear separately.

Unfortunately your suggestion doesn't work, because its a div that wraps everything, so clicking anywhere obviously turns it on.

<div type="button" data-toggle-class data-toggle-escape data-toggle-target=" .whole-page, .navigation-panel_holder, .navigation-panel_main, body" class="whole-page" data-toggle-outside>

Ideally i only want the one above to function when it has an is-active class on it.

@Twikito
Copy link
Owner

Twikito commented Jul 6, 2018

Ok, is this what you need ? https://codepen.io/Twikito/pen/VdJVop

@unijez
Copy link
Author

unijez commented Jul 6, 2018

Yes! Perfect, how does the day area know to close it again?

@Twikito
Copy link
Owner

Twikito commented Jul 6, 2018

It's a CSS pseudo element inside the trigger button 😉

@unijez
Copy link
Author

unijez commented Jul 8, 2018

Amazing, thank you :)

@Twikito Twikito closed this as completed Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants