【发布时间】:2010-12-29 23:40:13
【问题描述】:
我有以下代码来获取宽度中心
function alertSize() {
var myWidth = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
}
return myWidth/2;
}
但它没有返回正确的屏幕中心。
我需要得到正确的水平中心。
谢谢
【问题讨论】:
-
你的意思可能是“javascript”而不是“java”标签
-
您是指“屏幕中心”还是“浏览器窗口中心”?为什么提到 jQuery 而您的代码与它无关?我错过了什么吗?
标签: javascript jquery window center