我需要帮助居中我的javascript弹出在屏幕上。当我向下滚动屏幕并点击激活onclick弹出窗口的链接时,它会出现在我页面的顶部(在那里我看不到弹出窗口)。我怎么才能让这个弹出在我的屏幕中心,即使我是向下滚动。
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">
发布于 2014-10-12 09:44:01
您需要添加css以将弹出/模式定位到页面的中心。如下所示:
.Absolute-Center {
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}示例:http://jsfiddle.net/e9ftscov/
我使用的CSS代码的源代码和解释:http://codepen.io/shshaw/full/gEiDt
发布于 2014-10-12 09:44:20
你应该在弹出的父级中使用position:fixed。试试这个:
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display="block";document.getElementById('light').style.position="fixed";document.getElementById('fade').style.display="block";">如果没有,您可以使用css样式表:
.light{
position:fixed;
}https://stackoverflow.com/questions/26320926
复制相似问题