Skip to content

Instantly share code, notes, and snippets.

@mrlagmer
Last active July 21, 2017 00:11
Show Gist options
  • Save mrlagmer/3f1d04774ef28977dae2cef2edac8710 to your computer and use it in GitHub Desktop.
Save mrlagmer/3f1d04774ef28977dae2cef2edac8710 to your computer and use it in GitHub Desktop.
Mutation Observer
var el = document.getElementById('aniBox');
var adBox = document.getElementById('adBox');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.attributeName == 'style'){
var s = el.getAttribute('style');
if(s.search('height: 360px') != -1) {
adBox.style = 'display: block';
}
else {
adBox.style = 'display: none';
}
}
});
});
// configuration of the observer:
var config = { attributes: true, attributeFilter: ['style']};
// pass in the target node, as well as the observer options
observer.observe(el, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment