Skip to content

Instantly share code, notes, and snippets.

@hyeonseok
Created January 15, 2016 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyeonseok/4f80f5f697c9d873330f to your computer and use it in GitHub Desktop.
Save hyeonseok/4f80f5f697c9d873330f to your computer and use it in GitHub Desktop.
Open layer, then close layer by clicking document.
// TODO: Add complete HTML document.
$layer: $('.layer'),
$button: $('.button'),
_initialize: function() {
$(document).on('click', this._onClick.bind(this));
},
_onClick: function(event) {
var $target = $(event.target),
isLayer = $target.is(this.$layer) || $target.parents().is(this.$layer),
isButton = ($target.is(this.$button) || $target.parents().is(this.$button));
if (isLayer) {
return;
}
if (isButton && !this.$layer.is(':visible')) {
this.$layer.show();
} else {
this.$layer.hide();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment