Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).on("click",".js_popup-trigger", function(e){
- e.preventDefault();
- //Set variables
- var element = $(e.currentTarget).closest('.js_popup-trigger'),
- container = element.parent('.js_popup-container'),
- menu = element.next('.js_popup-menu');
- //Toggle the menu
- menu.fadeToggle(100);
- //Add the open classes to the container and trigger
- container.toggleClass('js_popup-container--open');
- element.toggleClass('js_popup-trigger--open');
- /* Create a click listener for the document
- * This is to close the menu if clicked outside of it */
- $(document).click(function closePopup(e){
- //If the clicked item is not in the popup, close it
- if(!$(e.target).closest(container[0]).length && element.is(":visible")){
- //Close the popup
- menu.fadeOut(100);
- //Remove the added classes
- container.removeClass('js_popup-container--open');
- element.removeClass('js_popup-trigger--open');
- //Unbind the closePopup function from the document
- $(document).unbind('click',closePopup);
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement