Last active
August 29, 2015 14:09
-
-
Save christophervigliotti/f6a866d2acb879eb29a3 to your computer and use it in GitHub Desktop.
Dirt-Simple Overlay
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
.overlay { | |
background-color:white; | |
filter:alpha(opacity=50); /* IE */ | |
opacity:0.5; /* Safari, Opera */ | |
-moz-opacity:0.50; /* FireFox */ | |
z-index:20; | |
height:100%; | |
width:100%; | |
background-repeat:no-repeat; | |
background-position:center; | |
position:absolute; | |
top:0px; | |
left:0px; | |
} |
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
...your html here... | |
<body> | |
<div id="overlay" class="overlay" style="display:none;"></div> | |
<link rel="stylesheet" type="text/css" href="overlay.css" /> | |
<script type="text/javascript" src="overlay.js"></script> | |
...your html here... |
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 the overlay | |
function showOverlay(){ | |
overlayVisible = true; | |
$('#overlay').show(); | |
} | |
// hides the overlay | |
function hideOverlay(){ | |
overlayVisible = false; | |
$('#overlay').hide(); | |
} | |
// show whenever ajax starts | |
$(document).ajaxStart(function() { | |
showOverlay(); | |
}); | |
// hide whenever ajax is done | |
$(document).ajaxComplete(function() { | |
hideOverlay(); | |
}); | |
// when an html element with the data-show-overlay-on-click="true" attribute is present, show that overlay! | |
$(document).on('click', '[data-show-overlay-on-click="true"]', function () { | |
showOverlay(); | |
}); | |
// onbeforeunload is not the best cross-platform solution...but this will show the overlay when a page refresh begins (fancy) | |
$(window).bind('beforeunload', function(){ | |
showOverlay(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment