Created
February 26, 2014 17:02
-
-
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
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
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