Skip to content

Instantly share code, notes, and snippets.

@bluespore
Last active December 14, 2015 10:08
Show Gist options
  • Save bluespore/5069438 to your computer and use it in GitHub Desktop.
Save bluespore/5069438 to your computer and use it in GitHub Desktop.
Closing interactive pop out/up areas such as modals and menus with jQuery.
/*
UX: Dealing with dynamic pop ups.
Clicking/touching the html will close anything
with a class of 'open'
Sean Bullock
*/
$('html').on('click touchstart', function(){
$('.open').removeClass('open');
});
/*
Be sure to include the elements here that you
want to interact with, e.g: modal with a form,
so as clicking inside it will not remove the open state.
Sean Bullock
*/
$('.element1, .element2').on('click touchstart', function(e){
e.stopPropagation();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment