Check whether or not the document has finished loading
$ npm install @f/is-dom-loaded
var isDomLoaded = require('@f/is-dom-loaded')
var loaded = isDomLoaded()
var fns = []
if (!loaded) {
document.addEventListener('DOMContentLoaded', function listener () {
document.removeEventListener('DOMContentLoaded', listener)
fns.forEach(function (fn) {
fn()
})
})
}
function domready () {
loaded ? setTimeout(fn) : fns.push(fn)
}
Returns: Boolean indicating whether or not the document has finished loading
MIT