最好使用 jQuery,因为它更容易理解。
以下内容非常适合水平放置。问题是垂直方向可能会在顶部被切断,需要用户向上滚动才能看到整个弹出窗口。
function pop_IT(X,event){
dist_to_right_edge = $('body').innerWidth()-(x-$.scrollbarWidth());
dist_to_bottom = $(window).height()-y;
X=$('#'+X).get(0);
X.style.left = 5+x+"px";
X.style.top = 5+y+"px";
if(dist_to_right_edge < (X.offsetWidth+5)){X.style.left = x - X.offsetWidth-5+"px";}
if(dist_to_bottom < (X.offsetHeight+5)){X.style.top = y - X.offsetHeight-5+"px";}
}
然后我加载类似的东西
$('#object').load('../whatever.php',function(event){pop_IT('object',event);});
应该很简单
<div class="popup" > test</div>
.popup
{
position:absolute;
width:400px;
height:400px;
}
jquery:
获取父元素的偏移量,我的意思是单击元素
$("#yourclickdiv").click(function (e) {
var offset = $(this).offset();
$(#popup).css('left',offset.left);
$(#popup).css('top',offset.top);
});
这应该可以做到。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)