【问题标题】:Javascript - Detect when the style changes are reflected?Javascript - 检测何时反映样式更改?
【发布时间】:2013-05-08 02:23:46
【问题描述】:

我有一个浏览器扩展程序,可以截取可见页面的屏幕截图(使用浏览器的 API)。

用户通过注入网页的自定义上下文菜单启动流程。

wrapper.addEventListener("contextmenu", function(e) {
    //prevent default context menu
    e.preventDefault();
    menu.style.display = "block";
});

menu.addEventListener("click", function click(e) {
    e.preventDefault();
    e.stopPropagation();
    //prevent the appearance of the menu in the screenshot
    menu.style.display = "none";
    capture();
}, false);

问题是菜单在屏幕截图中仍然可见。有没有办法检测何时反映样式更改?

谢谢。

【问题讨论】:

标签: javascript css google-chrome


【解决方案1】:

我通过在父元素上附加一个额外的监听器解决了这个问题(但不知道为什么它会起作用)

wrapper.addEventListener("contextmenu", function(e) {
    //prevent default context menu
    e.preventDefault();
    menu.style.display = "block";
});

wrapper.addEventListener("mousedown", function(e) {
    //can't use "display: none" before mouseup
    menu.style.opacity = 0;
}, false);

menu.addEventListener("click", function click(e) {
    e.preventDefault();
    e.stopPropagation();
    //prevent the appearance of the menu in the screenshot
    menu.style.display = "none";
    capture();
}, false);

【讨论】:

    【解决方案2】:

    很可能将调用capture 放在setTimeout 中并适当延迟会为您解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 2022-01-05
      相关资源
      最近更新 更多