Break when style has changed in Chrome Dev Tools

前端 未结 2 1075
走了就别回头了
走了就别回头了 2020-12-29 01:26

I just wonder if anyone know if it\'s possible to add a break point on a specific css property on a specific element in Chrome Dev Tools, i.e when #mydiv\'s hei

相关标签:
2条回答
  • 2020-12-29 02:04

    You can only break on all inline style (<div style="height: 20px; width: 100%">) changes using the Elements panel context menu's Break on... | Attributes modifications.

    0 讨论(0)
  • 2020-12-29 02:09

    You can do it this way:

    function observe(el, property) {
        var MutationObserver = window.WebKitMutationObserver;
    
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                console.log('old', mutation.oldValue, 'new', mutation.target.style.cssText, 'mutation', mutation);
                if (mutation.attributeName == property) debugger;
            });
        }
        );
    
        var config = {
            attributes: true,
            attributeOldValue: true
        }
    
        observer.observe(el, config);
    }
    

    Then you can set breakpoint on style change like this: observe(element, "style")

    It will break when it changes and also print in console old and new value.

    0 讨论(0)
提交回复
热议问题