views:

92

answers:

2

i have following code to get center of width

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

but it did't return correct center of screen.

what i need to get correct center horizontal.

thanks

A: 

Maybe this is helpful: A simple jQuery Client Centering Plugin

The MYYN
+1  A: 

Try this:

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

jQuery has already done all the extra work for you.

fudgey