Skip to content

Instantly share code, notes, and snippets.

@jorgepinon
Created February 26, 2014 17:02
Show Gist options
  • Save jorgepinon/9233695 to your computer and use it in GitHub Desktop.
Save jorgepinon/9233695 to your computer and use it in GitHub Desktop.
simple utility for adding an overlay to help focus user on a page element
function toggleOverlay() {
if (document.getElementById('overlay') != null) {
console.log(true);
$('#overlay').fadeOut(300,function(){
$(this).remove()
});
} else {
var overlay = document.createElement('div');
overlay.id = 'overlay';
overlay.className = 'mfp-bg'; /* use existing styles */
$(overlay).css({'opacity': 0.7, 'z-index':1}).prependTo('body');
}
}
// can be used with data attribute:
<a class="trigger-widget" data-overlay="true">Open widget</a>
<script>
$('a').on('click',function(){
if (el.data('overlay') == true) {
toggleOverlay();
}
...
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment