currentStyle in IE is null

2019-07-02 21:08发布

I am trying to caculate the current style of an element:

function cssIsLoaded(c) {
    if (window.getComputedStyle) {
        return window.getComputedStyle(c, null).display === "none";
    }
    else if (c.currentStyle) {

    }

    return true;
}

(function() {
    var cssload = document.createElement("div");
    cssload.className = "_css_loaded";
    checkLoaded();

    function checkLoaded() {
        if (!cssIsLoaded(cssload)) setTimeout(function() {
            checkLoaded();
        }, 20);
        else blalbalblbalbalablbal();
    }
})();

IE doesnt get into the 2nd condition, c.currentStyle is null... why is that?

1条回答
小情绪 Triste *
2楼-- · 2019-07-02 21:37

An element doesn't get its currentStyle property populated until it's added to the document, which makes some sense: until the element's been added to the document, the browser cannot know which existing style rules will apply to it.

查看更多
登录 后发表回答