Dynamic assignment of pop-up window position

When we click a button to start a pop-up window, pop-up window, and want to control the position of your pop-up window according to your browser page:

   1. First get the page size, height and width:

var X = $(document).height();
var Y = $(document).width();

    2. Control the top left of the pop-up window according to where you want to place the pop-up window (taking the center of the pop-up window as an example)

var XX= ($(document).height()/2)-300;
var YY = ($(document).width()/2)-300;

Among them, 300 is one-half of the height and width of your pop-up window;

3. Control css based on popup ID through jquery

$('#weixin_pay_qr').css("top", X);
$('#weixin_pay_qr').css("left", Y);
        $("#weixin_pay_qr").css({
               display : "block"
            });

Of course, you can change the pop-up window position according to your needs

4. Final effect


  The disadvantage is that the fixed value generated by js is only determined when the top left is entered when the page is entered. When you zoom the page, it will not be adaptive.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325556654&siteId=291194637