开发者

display div according to scrolbar location

I want to display a pop up window (div) using jquery animate ('top' and 'left' according to the user loaction )

I want this popup (top position) to be display according to the user location in the page(if the user scroll down the page ,the poup will be display in the user's location on this page)

I tried to take the mouse coordinates,in firefox it works fine, since the location of the mouse is absolote to the top of the screen,but in IE the coordinate of the mouse is relative to the top of the screen where the user's location is.

this is the code for taking the mouse coordinate

function getMouseXY(e) {

if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;

tempY = event.clientY + document.body.scrollTop;

} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
// catch possible negative values in NS4
if (tempX < 0) { tempX = 0 }
if (tempY 开发者_高级运维< 0) { tempY = 0 }

}

How can I use the animate top and left, relative to the user location in IE?

Thanks for any help


You don't need to know mouse pointer position if you can detect window size un scrollbar state.

function getPosition(){
  var width = 100; // popup width
  var height = 100; // popup height

  return {
    top: (($(window).height()-height)/2)+$(document).scrollTop(),
    left: (($(window).width()-width)/2)+$(document).scrollLeft()
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜