Jquery implements a pop up div that always displays a simple instance right in the middle of the screen


The following code block can always make the pop-up div in the center of the screen, I hope to help you!

    //Keep the specified DIV in the center of the screen.  
    function setDivCenter(divName){  
        var top = ($(window).height() - $(divName).height())/2;  
        var left = ($(window).width() - $(divName).width())/2;  
        var scrollTop = $(document).scrollTop();  
        var scrollLeft = $(document).scrollLeft();  
        $(divName).css( { position : 'absolute', 'top' : top + scrollTop, left : left + scrollLeft } ).show(); 
    }