1 $(document).ready(function(){
2
3 $('html').click(function(e){
4 mouseX=e.pageX;
5 mouseY=e.pageY;
6 var bodyTop = document.documentElement.scrollTop + document.body.scrollTop;
7 ..
8 //window.outerWidth is not working in IE
9 var windowWidth = $(window).outerWidth();
10 var windowHeight = $(window).outerHeight();
11 ..
12 if(mouseY-bodyTop+popupHeight > windowHeight)
13 ...
14 ...
15 //set the position first. remove the position attr in css
16 $('div').css({position:"absolute",top:popupTop,left:popupLeft});
17 $('div').show();
18 });
19 });
20