2

このコードを使用して、いくつかの要素の計算された境界半径の状態を取得しようとしています:

function _elementCurrentStyle(element, styleName){
    if (element.currentStyle){
        var i = 0, temp = "", changeCase = false;
        for (i = 0; i < styleName.length; i++)
            if (styleName[i].toString() != '-'){
                temp += (changeCase ? styleName[i].toString().toUpperCase() : styleName[i].toString());
                changeCase = false;
            } else {
                changeCase = true;
            }
        styleName = temp;
        return element.currentStyle[styleName];
    } else {
        return getComputedStyle(element, null).getPropertyValue(styleName);
    }
}

    var borderRadiusCheck = ["-moz-border-radius-bottomright","border-radius","border-bottom-right-radius","-webkit-border-bottom-right-radius","-khtml-border-radius-bottomright","-khtml-border-bottom-right-radius"];
    var i = 0, temp = "";
    for (i = 0; i < borderRadiusCheck.length; i++){
        temp = _elementCurrentStyle(myElement, borderRadiusCheck[i]);
        if (temp)
            break;
    }

変数「myElement」は、border-radius が「20px」に設定された HTML 要素です。(動的に設定するか、CSSを使用して設定するかのいずれか)

「temp」変数には、borderRadius (「20px」) 文字列が含まれます。このコードは IE、FF、および Chrome で動作しますが、Opera では、"border-radius" または "border-bottom-right-radius" を取得しようとすると空の文字列が返され、それ以外で呼び出すと "undefined" が返されます。

この HTML 要素の境界線はすべて同じであるため、border-radius または border-bottom-right-radius を取得しても問題ありません。

半径を取得するためにどのスタイル プロパティ名を呼び出せばよいかわかりましたか?

ご協力いただきありがとうございます。

4

1 に答える 1

0

Opera はborder-radiusをサポートしています。Opera Dragonflyを使用すると、次のことがわかります。

border-radius: 10px;

として変換されます

border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
于 2011-10-26T03:09:58.063 に答える