Created
November 6, 2012 04:10
-
-
Save mikermcneil/4022488 to your computer and use it in GitHub Desktop.
Cover the current page in a semi-transparent, black veil
This file contains hidden or 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
| // ************************************ | |
| // To use this code, run drawVeil(opacity,callback) | |
| // ************************************ | |
| function drawVeil(opacity,cb) { | |
| // Use 0.5 by default | |
| opacity = opacity || 0.5; | |
| // If jQuery doesn't exist, get it | |
| (window.jQuery && window.jQuery("body")) ? drawVeilHelper(opacity,cb) : loadScript("https://stripe.com/javascripts/jquery.js",function(){drawVeilHelper(opacity,cb)}); | |
| } | |
| // Call drawVeil logic directly | |
| function drawVeilHelper(opacity,cb) { | |
| // Create veil (delete any existing veils) | |
| jQuery("#veil-liev").remove(); | |
| var veil = jQuery("<div id='veil-liev'></div>"); | |
| // Style veil | |
| veil.css({ | |
| "z-index": 100000, | |
| width: "100%", | |
| height: "100%", | |
| background: "black", | |
| top: 0, left: 0, | |
| position: "fixed", | |
| opacity: 0 | |
| }); | |
| // Append veil | |
| jQuery("body").append(veil); | |
| veil = jQuery("#veil-liev"); | |
| veil.fadeTo(250,opacity); | |
| // Provide access to veil in callback | |
| cb && cb(veil); | |
| } | |
| // loadScript | |
| function loadScript(src,optionalCallback) { var s = document.createElement("script"); s.type = "text/javascript"; s.src = src; var context = document.getElementsByTagName('script')[0]; context.parentNode.insertBefore(s, context); s.async=true; s.addEventListener('load',optionalCallback); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment