The following code block will always keep the pop-up div in the center of the screen. I hope it will be helpful to everyone!
//Always display the specified DIV in the middle 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();
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn