Close menu on click outside of menu area

  • cme
  • cme's Avatar Offline Topic Author
  • New Member
  • New Member
  • Posts: 9
  • Thanks: 0

Replied by cme on topic Close menu on click outside of menu area

Posted 8 years 7 months ago #29976
Thanks for the input. When firing the click event using
Code:
$('li.accordeonck.open').trigger('click');
I always ended up in an endless recursion, although I don't have a clue why...

But I think I found a pretty simple solution. At least it seams to work so far:
Code:
$( "body" ).click(function( event ) { if(!event.target.hasClass("toggler")){ $('li.accordeonck.open').removeClass('open'); $('ul.content_1').hide(); } });

I will test it a little more before going live.

cme
by cme

Please Log in or Create an account to join the conversation.

  • cme
  • cme's Avatar Offline Topic Author
  • New Member
  • New Member
  • Posts: 9
  • Thanks: 0

Replied by cme on topic Close menu on click outside of menu area

Posted 8 years 7 months ago #30010
For some reason not working on iPads. Desktops and android tablets are fine.

I extended the if condition a little bit in order to keep the menu open until a new page is loaded if a link is clicked.
Code:
<script type="text/javascript">jQuery(function($){ $( "body" ).click(function( event ) { if(!event.target.hasClass("toggler")&&event.target.nodeName!="A"){ $('li.accordeonck.open').removeClass('open'); $('ul.content_1').hide(); } }); });</script>

cme
Last Edit:8 years 7 months ago by cme
Last edit: 8 years 7 months ago by cme.

Please Log in or Create an account to join the conversation.

Replied by ced1870 on topic Close menu on click outside of menu area

Posted 8 years 6 months ago #30011
thank you for sharing your solution. As you can see, it is not so easy to do that ;)

Joomlack Webmaster and Developer

by ced1870

Please Log in or Create an account to join the conversation.

Time to create page: 0.672 seconds

Fast and powerful creation, customizable and responsive.

Read More

We have 472 guests and no members online