Last active
January 30, 2018 17:37
-
-
Save evantbyrne/7290fcb8957f3bfc80259bfd969dde03 to your computer and use it in GitHub Desktop.
DOM ready
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
// Example using the module. | |
import domready from "./domready.js"; | |
domready(function() { | |
//... | |
}); |
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
// Runs `callback` once DOM has been loaded. | |
// Supported by IE9+ and modern browsers. | |
export default function(callback) { | |
if(document.readyState === "complete") { | |
callback(); | |
} else { | |
document.addEventListener("DOMContentLoaded", callback); | |
} | |
} |
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
// Example without using the module. | |
function ready() { | |
//... | |
} | |
if(document.readyState === "complete") { | |
ready(); | |
} else { | |
document.addEventListener("DOMContentLoaded", ready); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment