Open popup at clicked position

前端 未结 2 1914
予麋鹿
予麋鹿 2021-02-04 10:17

Hi,

I have done a popup which is by default hidden and opened whenever a click is triggered on window. Popup must be shown at wherever the event is triggered.But there

2条回答
  •  一个人的身影
    2021-02-04 10:33

    maybe you can load the windowW/H in the init time and out of your function.

    The concept is use the mouseY-scrolled high, because the mouseY is related to the body.so use this:

     $(document).ready(function(){
    
         $('html').click(function(e){
          mouseX=e.pageX;
          mouseY=e.pageY;
          var bodyTop = document.documentElement.scrollTop + document.body.scrollTop;
          ..
          //window.outerWidth is not working in IE
          var windowWidth  = $(window).outerWidth();
          var windowHeight = $(window).outerHeight();
          ..
          if(mouseY-bodyTop+popupHeight > windowHeight)
            ...
            ...
          //set the position first. remove the position attr in css   
          $('div').css({position:"absolute",top:popupTop,left:popupLeft});
          $('div').show();
         });
     });
    

提交回复
热议问题