覆盖属性CSSStyleDeclaration.textShadow? [英] Override property CSSStyleDeclaration.textShadow?

查看:197
本文介绍了覆盖属性CSSStyleDeclaration.textShadow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以覆盖JavaScript中CSSStyleDeclaration对象的textShadow属性?

Is it possible to override the textShadow property of a CSSStyleDeclaration object in JavaScript?

我尝试了以下操作:

var element = document.createElement('div');
Object.defineProperty(element.style, 'textShadow', {
    get: function() {
        console.warn("Getter called");
        return "";
    },
    set: function(value) {
        console.log("Setter called");
    },
    configurable: true
});

element.style.textShadow = "black 3px 3px 10px"; // Works as usual

如最后一行所述,属性的覆盖不真正工作。我发现textShadow不是CSSStyleDeclaration元素的自己的属性,但它来自CSS2Properties接口。但是,我不知道如何获取CSS2Properties接口...

As already stated in the last line, the override of the property does not really work. I found out that textShadow is not an own property of the CSSStyleDeclaration element, but it comes from the CSS2Properties interface. However, I don't know how to get the CSS2Properties interface ...

编辑:我在Firefox 7.0.1和Chrome在Chrome中它不工作,但是FF 8工作得很好。

EDIT: I have tested on Firefox 7.0.1 and Chrome 15. In Chrome it won't work, but FF 8 does work well.

有没有更通用的方法来覆盖所有元素的所有textShadow属性?我可以遍历每个HTMLElement并覆盖textShadow属性,但我想要一个更方便的方法。

Is there a more generic way to override all textShadow properties of all elements? I can iterate over each HTMLElement and override the textShadow property, but I would like a more convenient way.

推荐答案

从Chrome浏览器中的错误(见帖子)。
在Firefox 8中,代码按预期工作。

My problem was arising from a bug in the Chrome browser (see post). In Firefox 8 the code works as expected.

这篇关于覆盖属性CSSStyleDeclaration.textShadow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆