-
-
Save sandro-pasquali/6551847 to your computer and use it in GitHub Desktop.
Cross-browser CSS-loaded detector, without browser sniffing.
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
#targ { | |
position: absolute; | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<script type="text/javascript"> | |
function loadCSS(src, cb) { | |
var head = document.getElementsByTagName('head')[0]; | |
var link = document.createElement('link'); | |
link.setAttribute('href', src); | |
link.setAttribute('rel', 'stylesheet'); | |
link.setAttribute('type', 'text/css'); | |
link.setAttribute('charset', 'utf-8'); | |
head.insertBefore(link, head.firstChild); | |
(function check() { | |
if(link[document.createStyleSheet ? 'styleSheet' : 'sheet']) { | |
return cb && cb(link); | |
} | |
setTimeout(check, 0); | |
})(); | |
} | |
setTimeout(function() { | |
loadCSS('style.css', function(link) { | |
var el = document.getElementById("targ"); | |
el.style.left = "100px"; | |
}); | |
}, 1000); | |
</script> | |
</head> | |
<body> | |
<div id="targ">left?</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment