performancegoogle-chromecomputed-style

Too slow when getting current style on Chrome using javascript


I am stuck with a stupid problem. Below is my code to get computed style of a dom. It run well on FireFox and even IE (surprised)! but too slow on chrome v17 (20x time slower). How to avoid the problem?

getCurrentStyle = function(el)
{
    if (el.currentStyle)
        return el.currentStyle;
    else if (window.getComputedStyle)
        return document.defaultView.getComputedStyle(el,null);
    return null;
}

Solution

  • It is a Chrome bug. So that we avoid to use this function:

    document.defaultView.getComputedStyle(el,null)