在Chrome开发工具中更改样式时中断

bjo*_*lom 37 debugging google-chrome-devtools

我只是想知道是否有人知道是否可以在Chrome Dev Tools中的特定元素上的特定css属性上添加断点,即当#mydiv'sheight属性发生更改时,中断.

Ale*_*lov 34

您只能<div style="height: 20px; width: 100%">使用"元素"面板上下文菜单的Break on...| 来中断所有内联样式()更改 Attributes modifications.

  • 这对我来说似乎不起作用:(我看到`style ="overflow:hidden;"`被添加到我的`<body>`标签,它有一个属性修改断点,但我什么都没得到.我最终找到了什么虽然正在添加它,但是当加载iframe时,我猜Chrome没有正确处理这种情况:`iframe.attr("onload","this.style.visibility ='visible'; parent.document.body .style.overflow ='hidden';");` (2认同)
  • 感谢您的注意!欢迎您在http://crbug.com/new上通过详细的repro步骤为此提交错误.附加到bug的失败案例将会很有帮助. (2认同)

eli*_*xon 11

你可以这样做:

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);
}
Run Code Online (Sandbox Code Playgroud)

然后你可以像这样在样式更改上设置断点: observe(element, "style")

它会在更改时中断,并且还会在控制台中打印旧值和新值。