Last active
July 21, 2017 00:11
-
-
Save mrlagmer/3f1d04774ef28977dae2cef2edac8710 to your computer and use it in GitHub Desktop.
Mutation Observer
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
| 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