Created
January 15, 2016 10:12
-
-
Save hyeonseok/4f80f5f697c9d873330f to your computer and use it in GitHub Desktop.
Open layer, then close layer by clicking document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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