0

我有以下代码来获得宽度的中心

  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;
}

但它没有返回正确的屏幕中心。

我需要得到正确的中心水平。

谢谢

4

2 回答 2

3

试试这个:

function alertSize() {
 return $(window).width()/2
}

jQuery 已经为您完成了所有额外的工作。

于 2009-12-25T13:34:15.727 回答
0

也许这有帮助:A simple jQuery Client Centering Plugin

于 2009-12-25T12:40:40.203 回答