我正在尝试使用以下代码计算某些元素的border-radius状态:
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”是一个HTML元素,border-radius设置为“20px”。 (通过动态设置和使用CSS)
“temp”变量包含borderRadius(“20px”)字符串。 此代码在IE,FF和Chrome下工作,但在Opera下,我在尝试获取“border-radius”或“border-bottom-right-radius”时得到一个空字符串,当与其他人调用时,它返回“undefined”。
如果我得到border-radius或border-bottom-right-radius,则无关紧要,因为此HTML元素的所有边框都相同。
您有什么想法,我应该使用哪种样式属性名称来获取半径?
感谢您的帮助。
答案 0 :(得分: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;