【问题标题】:get computed border radius in opera在歌剧中获得计算的边界半径
【发布时间】:2011-03-10 16:37:10
【问题描述】:

我正在尝试使用以下代码计算某些元素的边界半径状态:

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”是一个边框半径设置为“20px”的 HTML 元素。 (通过动态设置和使用 CSS)

“temp”变量包含borderRadius(“20px”)字符串。 这段代码在 IE、FF 和 Chrome 下工作,但在 Opera 下,我在尝试获取“border-radius”或“border-bottom-right-radius”时得到一个空字符串,并且在与其他人调用时返回“undefined”。

我得到border-radius或border-bottom-right-radius都没有关系,因为这个HTML元素的所有边框都是相同的。

您知道我应该调用哪个样式属性名称来获取半径吗?

感谢您的帮助。

【问题讨论】:

    标签: javascript opera css computed-style


    【解决方案1】:

    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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      相关资源
      最近更新 更多