Created
March 8, 2015 01:54
-
-
Save ssmylh/a63c290c542a57e0f143 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
| <!doctype html> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>MutationObserver Sample</title> | |
| <script> | |
| /* https://developer.mozilla.org/ja/docs/Web/API/MutationObserver */ | |
| document.addEventListener('DOMContentLoaded', start); | |
| function start() { | |
| var mo = new MutationObserver(function(mutations, observer) { | |
| mutations.forEach(function(mutation) { | |
| console.log('set display none.') | |
| mutation.target.style.display = 'none'; | |
| }); | |
| // Clear this MutationObserver instance's record queue, | |
| // in order to prevent this callback from being called infinitely. | |
| observer.takeRecords(); | |
| }); | |
| var target = document.getElementById('target'); | |
| var config = { attributes: true }; | |
| mo.observe(target, config); | |
| setInterval(function() { | |
| console.log('set display block.'); | |
| target.style.display = ''; | |
| }, 5000); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <span id="target" style="display:none">text</span> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment