我有一些与此结构相关的弹出窗口:
<div id="pop_cont" class="popup_cont" >
<div id="pop" class="popup" >
<div class="xclose" ><img src="images/divclose.png" onclick="closediv('pop_cont');" title="chiudimi" /></div>
<div id="pop_title" class="popup_title" >TITLE</div>
<div id="pop_int" >SOME CONTENT</div>
</div>
</div>使用此css:
#alert_cont, .alert_cont, .popup_cont {
z-index:600;
position:fixed;
top:0px;
left:0px;
width:100%;
height:100%;
background-color:rgba(0,0,0,0.5);
display: none;
}
#alert, .alert, .popup{
position: absolute;
background-color: white;
border: 1px solid black;
border-collapse: collapse;
}
#alert_int, .alert_int, .popup_int{
padding:10px;
}
.xclose {
right: 1px;
top: 1px;
float: right;
cursor:pointer;
border:0px;
}
#alert_title, .alert_title, .popup_title{
background-color:#ffd600;
border:1px solid #ffe666;
color: #000000;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
text-align:center;
cursor: move;
}稍后,我移动我得到的弹出窗口,获取"class=' popup _title'“div并移动父元素。使用这种脚本:
var oDrag = null
var x,y,dx,dy
function mdown(e) {
if (!e) var e = window.event;
oDrag = (e.target) ? e.target : e.srcElement
if (oDrag.className=='popup_title'){
oDrag=oDrag.parentElement;
x = e.clientX;
y = e.clientY;
dx = x - parseInt(oDrag.style.left);
dy = y - parseInt(oDrag.style.top);
document.onmousemove=mdrag_on;
document.onmouseup=mdrag_off;
} else {
oDrag = null;
}
}
function mdrag_on(e) {
if (!e) var e = window.event;
oDrag.style.left = parseInt(e.clientX - dx)+'px';
oDrag.style.top =parseInt(e.clientY - dy)+'px';
return false
}
function mdrag_off(e) {
document.onmousemove=null;
}非常简单,但它是有效的。问题是,当我接近屏幕的边缘时,我正在移动的div get会被压缩,而不是离开屏幕。它被压缩,直到可以,包装文本,当它不再可能时,它会离开屏幕。当我回去的时候,它会尽快回到标准尺寸。有什么方法可以避免这种情况吗?比如为我要移动的div设置一些css?
发布于 2013-08-21 20:23:51
好了,我解决了。或者我真的没有解决,但我发现了设计错误和某种解决方案。我有一个容器,当弹出窗口出现时,它基本上是覆盖所有东西的大阴影。弹出窗口是这个阴影的子级,所以当我移动到屏幕的边缘时,实际上我会移动到阴影的边缘,web浏览器当然会尝试让弹出窗口停留在它里面。所以我给了
width:300%添加到我的“影子”容器,现在它看起来很好。(奇怪的是,在左侧和底部,它没有发生...)
因此,现在真正的解决方案是使阴影不是弹出窗口的父对象,但这需要在每次我需要显示弹出窗口时使用would .display=‘block’(这有什么大不了的?)或者保持这个宽度:300%的人作为一些好的建议给我?
https://stackoverflow.com/questions/18340598
复制相似问题