获取 Opera 中计算的边界半径
我正在尝试使用以下代码获取某些元素的计算边框半径状态:
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 元素的所有边框都是相同的。
您知道我应该调用哪个样式属性名称来获取半径吗?
感谢您的帮助。
I'm trying to get computed border-radius state of some element with this code:
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;
}
The variable "myElement" is a HTML element with border-radius set to "20px". (Either by setting it dynamically and with CSS)
The "temp" variable contains the borderRadius ("20px") string.
This code works under IE, FF and Chrome, but under Opera, I get an empty string when trying to get "border-radius" or "border-bottom-right-radius", and when calling with others it returns "undefined".
It doesn't matter if I get border-radius or border-bottom-right-radius because all borders of this HTML element are the same.
Have You got any idea, which style property name should I call for to get the radius?
Thanks for Your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Opera 支持边框半径。当使用 Opera Dragonfly 时,您可以注意到它
被转换为
Opera supports border-radius. When using Opera Dragonfly, you can notice that
gets transformed as