Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="zh-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="xgqfrms">
    <meta name="generator" content="VS code">
    <title>Mutation Observer & customize resize event listener & demo</title>
    <style>
        ol {
            box-sizing: border-box;
            width: 110px;
            height: 110px;
            border: 1px solid red;
            padding: 10px;
            resize: both;
            overflow: auto;
        }
    </style>
</head>

<body>
    <section>
        <h1>Mutation Observer & customize resize event listener & demo</h1>
    </section>
    <section>
        <ol contenteditable oninput="">
            <li>Press enter</li>
        </ol>
    </section>
    <!-- js -->
    <script>
        const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
        // target
        const list = document.querySelector(`ol`);
        // options
        const config = {
            attributes: true,
            childList: true,
            characterData: true,
            subtree: true,
        };
        // instance
        const observer = new MutationObserver(function(mutations) {
            // console.log(`mutations =`, mutations); // MutationRecord
            mutations.forEach(function(mutation) {
                // console.log("mutation =", mutation);
                if (mutation.type === "characterData") {
                    // target & object === typeof(mutation.target)
                    // console.log("A child node has been added OR removed.", mutation.target, typeof(mutation.target));
                    // console.log("[...mutation.addedNodes].length", [...mutation.addedNodes].length);
                    // console.log("[...mutation.removedNodes].length", [...mutation.removedNodes].length);
                    // if (mutation.target && [...mutation.addedNodes].length) {
                    //     // [...mutation.addedNodes].length
                    //     console.log(`A child node ${mutation.target} has been added!`, mutation.target);
                    // }
                    // if (mutation.target && [...mutation.removedNodes].length) {
                    //     // [...mutation.removedNodes].length
                    //     console.log(`A child node ${mutation.target} has been removed!`, mutation.target);
                    // }
                }
                if (mutation.type === "childList") {
                    if (mutation.target && [...mutation.addedNodes].length) {
                        console.log(`A child node ${mutation.target} has been added!`, mutation.target);
                    }
                    if (mutation.target && [...mutation.removedNodes].length) {
                        console.log(`A child node ${mutation.target} has been removed!`, mutation.target);
                    }
                    // do somwthings
                    let list_values = [];
                    list_values = [].slice.call(list.children).map(function(node) {
                        return node.innerHTML;
                    }).filter(function(str) {
                        if (str === "<br>") {
                            return false;
                        } else {
                            return true;
                        }
                    });
                    console.log(list_values);
                }
                if (mutation.type === "attributes") {
                    console.log("mutation =", mutation);
                    console.log(`The \`${mutation.attributeName}\` attribute was modified.`);
                    // console.log("list style =", list.style);
                    let {
                        width,
                        height,
                    } = list.style;
                    let style = {
                        width,
                        height
                    };
                    console.log("style =\n", JSON.stringify(style, null, 4));
                }
            });
        });
        observer.observe(list, config);
        // Later, you can stop observing
        // setTimeout(() => {
        //     observer.disconnect();
        // }, 1000 * 100);
        // bug ??? after disconnect
        // list.attributes;
        // list.setAttribute(`style`, `height: 212px; width: 213px;`);
        // list.setAttribute(`data-test`, `666`);
        // list.removeAttribute(`data-test`);
        // list.children;
        // list.childElementCount;
        // list.childNodes;
        // list.hasChildNodes();
        // list.firstElementChild;
        // list.firstChild;
        // list.removeChild(li);
        // list.removeChild(list.firstElementChild);
        // list.replaceChild(li, li);
        // list.replaceChild(list.firstElementChild, list.lastElementChild);
    </script>
</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console