Last active
November 22, 2019 06:35
-
-
Save nightsh/751215991c7c21a30ea608cbbf6a425a to your computer and use it in GitHub Desktop.
javascript style observer
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
var styleObserver = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutationRecord) { | |
var computedStyle = window.getComputedStyle(target, null); | |
console.log(mutationRecord); | |
if (mutationRecord.target.style.display == 'block') { | |
console.log('block!'); | |
mutationRecord.target.focus(); | |
} | |
}); | |
}); | |
// By class name | |
var targets = document.getElementsByClassName("modal"); | |
var i; | |
for (i = 0; i < targets.length; i++) { | |
styleObserver.observe(targets[i], { attributes : true, attributeFilter : ['style'] }); | |
} | |
// By id | |
var target = document.getElementById('embed-{{ resource_view['id'] }}'); | |
styleObserver.observe(target, { attributes : true, attributeFilter : ['style'] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment