Last active
March 5, 2019 19:37
-
-
Save da411d/9bf77d1abd9c9299ce2ccc9385cc60c1 to your computer and use it in GitHub Desktop.
Ready from jQuery
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
function ready(fn){ | |
let done = false; | |
function act(){ | |
if(done)return; | |
done = true; | |
fn(); | |
} | |
if ( | |
document.readyState === "complete" || | |
(document.readyState !== "loading" && !document.documentElement.doScroll) | |
){ | |
window.setTimeout(act, 0); | |
} else { | |
document.addEventListener("DOMContentLoaded", act); | |
window.addEventListener("load", act); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment