div浮动框居于浏览器窗口中间


 

代码先贴这里,随后再改

<script language="JavaScript">
 document.getElementById('divCenter').style.left = (document.body.offsetWidth - 540) / 2; 
 document.getElementById('divCenter').style.top = (document.body.offsetHeight - 170) / 2 + document.body.scrollTop;
</script>
$('#tipb').css("top",$(document).scrollTop()+($(window).height())/2-50+"px");

1、scrollTop()的返回值是当前元素的滚动条距离其顶部的垂直距离(对象元素必须要有滚动条才行!)。如果是document的话也就是屏幕的最上方距离元素最上方的距离。

2、获取某元素距离文档最上方的垂直距离。

var offset = $("#abcd").offset();

var e_top=offset.top;
alert(offset.top);

3、获取当前窗口的高度

$(window).height();

4、获取当前窗口可视区域的最上方  距离 文档最上方  的距离。

$(document).scrollTop();

                                                                  by:yttsic

原文地址:https://www.cnblogs.com/yttsic/p/3481536.html