<!DOCTYPE html>

<html>

<head>

 <meta charset=”UTF-8″>

    <title></title>
</head>

 


 

<body>
    <div id=”target” style=”height: 200px; width: 600px;aqua; display: none;”></div>
    <div id=”test” style=”position: relative; display: block;” class=”show”>test</div>

    <script type=”text/javascript”>
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
        var element = document.querySelector(‘#test’);
        var target = document.querySelector(‘#target’)
        var observer = new MutationObserver(function (mutations) {
            mutations.forEach(function (mutation) {
                if (mutation.type == “attributes” ) {
                    console.log(mutation.target.style.display);
                    if(mutation.target.style.display == ‘none’){
                        testing.style.display = ‘none’
                    }else{
                        testing.style.display = ‘block’
                    }
                }
            });
        });
        observer.observe(element, {
            attributes: true 
        });
    </script>

</body>

 

</html>

 

版权声明:本文为web-zs原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/web-zs/p/12810021.html