Last active
December 27, 2015 06:49
-
-
Save lutsen/7284117 to your computer and use it in GitHub Desktop.
This jQuery based script shows an element, and hides it again by clicking anywhere in the <body>You can use it to show popovers or modals for example.In the example, if you click on any element with the class "info", a child element with the class "info-tip" is shown.
This file contains 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
// Shows an element, and hides it on clicking anywhere in the <body> | |
function toggleOnClick(target) { | |
// Show | |
$(target).fadeIn("fast", function() { | |
$('body').on('click', function() { | |
// Hide on click outside | |
$(target).fadeOut("fast"); | |
}); | |
}); | |
} | |
$(function (){ | |
// Show .info-tip on clicking .info | |
$('.info').on('click', function() { | |
toggleOnClick($(this).find('.info-tip')); | |
}); | |
}); |
This file contains 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
.info { | |
cursor: pointer; | |
} | |
.info-tip { | |
z-index: 1; | |
display: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment