这个也行<body onmousemove="moveIt();" onmouseup="end();" ondragstart="return false;"><script> var isDrag = false;var oldX=0,oldY=0; function init(){ isDrag=true; oldX=event.x; oldY=event.y; } function end(){ isDrag=false; } function moveIt(){ if(isDrag){ var x =window.event.x; var y = window.event.y;
楼上cat_hsfz(我的Blog在 http://dotNET.CatChen.biz) ( ) 的建议很好。
现在的浏览器安全性太高,所以popup快没有用了。
*****************************************************************************用功譬若掘井,与其多掘数井而皆不及泉,何若老守一井,力求及泉而用之不竭乎?
<head><style>
div.titleBar{background: #ffffff;margin: 0px auto;width: 100%;height: 21px;border: black solid 1px;}
div.closeButton{float: right;}
div.mainBody{margin: auto;}
#divModalDialog{border:solid 1px;background:white;POSITION: absolute;left:0px;top:0px;DISPLAY: none;z-index:49;height:200px;WIDTH: 350px;}
#divModal{BACKGROUND-COLOR: white; FILTER: alpha(opacity=75); LEFT: 0px; POSITION:absolute; TOP: 0px"}
</style><script>function showModel()
{
divModalDialog.style.display = "block";
resizeModal();
window.onresize = resizeModal;
}
function closeModel()
{
divModal.style.width = "0px";
divModal.style.height = "0px";
divModalDialog.style.display = "none";
window.onresize = null;
}
function resizeModal()
{
divModal.style.width = document.body.scrollWidth;
divModal.style.height = document.body.scrollHeight;
divModalDialog.style.left = ((document.body.offsetWidth - divModalDialog.offsetWidth) / 2);
divModalDialog.style.top = ((document.body.offsetHeight - divModalDialog.offsetHeight) / 2);
}
</script>
</head><body>
<input type="button" value="点击这里" onclick="showModel()" /><!-- 透明遮罩 -->
<DIV id="divModal"></div>
<!-- 透明遮罩 end --><!-- 模态窗口 -->
<DIV id="divModalDialog" >
<div class="titleBar">
<div class="closeButton"><a href="javascript:closeModel();">[关闭]</a></div>
</div>
<div class="mainBody">
在这里添加内容
</div>
</DIV><!-- 模态窗口 end -->
</body></html>
var isDrag = false;var oldX=0,oldY=0;
function init(){
isDrag=true;
oldX=event.x;
oldY=event.y;
}
function end(){
isDrag=false;
}
function moveIt(){
if(isDrag){
var x =window.event.x;
var y = window.event.y;
hdl.parentNode.style.left = parseInt(hdl.parentNode.style.left.replace("px","")) + (x - oldX);
hdl.parentNode.style.top = parseInt(hdl.parentNode.style.top.replace("px","")) + (y - oldY);
oldX = x;
oldY = y;
}
}
</script>
<div id="back" onmousemove="moveIt();" onmouseup="end();" style="position:absolute;left:0;top:0;width:1000;height:660;visibility:hidden;"> </div>
<div onmousedown="init();" onmousemove="moveIt();" onmouseup="end();" style="border:1px outset #333333;position:absolute;filter:alpha(opacity=70);top:0;left:0;width:400;height:300">
<div id="hdl" style="background:#333377;width:100%;height:20;color:white"><b>窗口</b></div>
<div style="background:#dddddd;width:100%;height:280">
<input type="button" value="变暗效果" onclick="back.style.background='#333333';back.style.filter='alpha(opacity=40)';back.style.visibility='';">
</div>
</div></body>