Jquery implements a pop up div that always displays a simple instance right in the middle of the screen
- 2020-03-30 02:18:33
- OfStack
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();
}