jquery实现弹出div,始终显示在屏幕正中间的简单实例_jquery
程序员文章站
2022-05-23 14:01:49
...
以下代码块就能始终让弹出div位于屏幕的正中心,希望对大家有所帮助!
//让指定的DIV始终显示在屏幕正中间
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();
}
复制代码 代码如下:
//让指定的DIV始终显示在屏幕正中间
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();
}