DIV 拖动 参数无效

cdmsan 2008-11-21 01:29:39
<style>
html,body{
margin: 0px;/*-- 取消页面边界 --*/
/*-- 滚动条样式 for IE 5.5+--*/
scrollbar-face-color: #f6f6f6;
scrollbar-highlight-color: #ffffff;
scrollbar-shadow-color: #cccccc;
scrollbar-3dlight-color: #cccccc;
scrollbar-arrow-color: #330000;
scrollbar-track-color: #f6f6f6;
scrollbar-darkshadow-color: #ffffff;
/*background-color: #00B2EB;-- 页面背景 --*/
}
body,td,th {
font-size: 12px;/*-- 页面字号 --*/
color: #000000;/*-- 页面字体颜色 --*/
font-family:Verdana, Arial, Helvetica, sans-serif;/*-- 页面字体 --*/
}
.Msg_Bg {
position:absolute;
left: 0;
top: 0;
width: 100%;
height:100%;
filter:alpha(opacity=60);
-moz-opacity:.6;
opacity:.6;
background-color: #cccccc;
z-index: 1;
position: absolute;
}
.Msg_Div_Coutent {
position:absolute;
left: 10%;
top: 10%;
-moz-opacity:.6;
opacity:.6;
z-index: 1;
position: absolute;
cursor:move;
background-color:#FF0000;
height:100px;
}
</style>
<script>
var Obj;
var MouseX;
var MouseY;
function MouseDown()
{
if(Obj!=null)
{
Obj.setCapture();
Obj.l=event.x-Obj.style.pixelLeft;
Obj.t=event.y-Obj.style.pixelTop;

}
}
function MouseMove()
{
if(Obj!=null)
{
Obj.style.left = event.x-Obj.l;
Obj.style.top = event.y-Obj.t;
}
}
function MouseUp()
{
if(Obj!=null)
{
Obj.releaseCapture();
Obj=null;
}
}

function CElement(TextHtml)
{
var shade = document.createElement('div');
var shade1 = document.createElement('div');
shade.className = "Msg_Bg";
shade.id ="MsgBoxF";
shade1.className = "Msg_Div_Coutent";
shade1.id ="MsgBoxC";

document.body.insertBefore(shade, document.getElementById("body"));
document.body.insertBefore(shade1, document.getElementById(shade));

var ptable = document.getElementById('shade1');
if (shade.style.display == 'none') return;
var ch = document.body.clientHeight, sh = document.body.scrollHeight, st=document.body.scrollTop;
shade.style.height = (sh > ch ? sh : ch) + 'px';
shade.style.width = document.body.clientWidth + 'px';
//shade1.style.width = document.body.clientWidth/2 + 'px';
var pos = [], pw;
if (ptable) {
pos = getPosXY(ptable);
pw = ptable.offsetWidth || 760;
} else {
pw = 500;
pos[0] = (document.body.clientWidth-pw)/2+50;
pos[1] = (ch-(shade1.offsetHeight || 300))/2-200;
}
if (navigator.product && navigator.product == 'Gecko') {
pw -= 40;
}
shade1.style.left = pos[0] + 'px';
shade1.style.top = pos[1] + 'px';
shade1.innerHTML=TextHtml;
Obj=shade1;
shade1.attachEvent("onmousedown",MouseDown);
shade1.attachEvent("onmousemove",MouseMove);
shade1.attachEvent("onmouseup",MouseUp);
}





</script>
<body><script language='javascript'>CElement("123123123");</script></body>


不知道为啥子,只能拖动一次,还提示参数无效
...全文
153 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lengssmm 2008-11-21
  • 打赏
  • 举报
回复
你又开了一个帖子啊- -| | |
你这次的问题是obj的问题了
第一次obj=shade1;这时候走down,move up没有问题,但是在up之后obj=null了
第二次obj=null; 你这时候程序怎么能走哪?

所以你只要在你的早先发的那个程序里稍微小改一下就可以了我建议你继续用原来的bIsCatchFlyBar那个变量
下面是我对你原先程序的修改


<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
html,body{
margin: 0px;/*-- 取消页面边界 --*/
/*-- 滚动条样式 for IE 5.5+--*/
scrollbar-face-color: #f6f6f6;
scrollbar-highlight-color: #ffffff;
scrollbar-shadow-color: #cccccc;
scrollbar-3dlight-color: #cccccc;
scrollbar-arrow-color: #330000;
scrollbar-track-color: #f6f6f6;
scrollbar-darkshadow-color: #ffffff;
/*background-color: #00B2EB;-- 页面背景 --*/
}
body,td,th {
font-size: 12px;/*-- 页面字号 --*/
color: #000000;/*-- 页面字体颜色 --*/
font-family:Verdana, Arial, Helvetica, sans-serif;/*-- 页面字体 --*/
}
.Msg_Bg {
position:absolute;
left: 0;
top: 0;
width: 100%;
height:100%;
filter:alpha(opacity=60);
-moz-opacity:.6;
opacity:.6;
background-color: #cccccc;
z-index: 1;
position: absolute;
}
.Msg_Div_Coutent {
position:absolute;
left: 10%;
top: 10%;
-moz-opacity:.6;
opacity:.6;
z-index: 1;
position: absolute;
cursor:move;
background-color:#FF0000;
height:100px;
}
</style>
<script language="javascript">
// JavaScript Document
function CElement(TextHtml)
{
var shade = document.createElement('div');
var shade1 = document.createElement('div');
shade.className = "Msg_Bg";
shade.id ="MsgBoxF";
shade1.className = "Msg_Div_Coutent";
shade1.id ="MsgBoxC";
document.body.insertBefore(shade, document.getElementById("body"));
document.body.insertBefore(shade1, document.getElementById(shade));
var ptable = document.getElementById('shade1');
if (shade.style.display == 'none') return;
var ch = document.body.clientHeight, sh = document.body.scrollHeight, st=document.body.scrollTop;
shade.style.height = (sh > ch ? sh : ch) + 'px';
shade.style.width = document.body.clientWidth + 'px';
//shade1.style.width = document.body.clientWidth/2 + 'px';
var pos = [], pw;
if (ptable) {
pos = getPosXY(ptable);
pw = ptable.offsetWidth || 760;
} else {
pw = 500;
pos[0] = (document.body.clientWidth-pw)/2+50;
pos[1] = (ch-(shade1.offsetHeight || 300))/2-200;
}
if (navigator.product && navigator.product == 'Gecko') {
pw -= 40;
}
shade1.style.left = pos[0] + 'px';
shade1.style.top = pos[1] + 'px';
//shade1.style.height =ch/2 + 'px';

MsgBoxC.attachEvent('onmousedown',MouseDown);
MsgBoxC.attachEvent('onmousemove',MouseMove);
MsgBoxC.attachEvent('onmouseup',MouseUp);
shade1.innerHTML=TextHtml;
}
var bIsCatchFlyBar = false;
var dragClickX = 0;
var dragClickY = 0;


function MouseDown(){
bIsCatchFlyBar = true;
var x=event.x+document.body.scrollLeft;
var y=event.y+document.body.scrollTop;

dragClickX=x-MsgBoxC.style.pixelLeft;
dragClickY=y-MsgBoxC.style.pixelTop;
MsgBoxC.setCapture();
//document.onmousemove =moveFlyBar;
}
function MouseUp(){
bIsCatchFlyBar = false;
MsgBoxC.releaseCapture();
// document.onmousemove = null;
}

function MouseMove(){

if(bIsCatchFlyBar){

MsgBoxC.style.left = event.x+document.body.scrollLeft-dragClickX;
MsgBoxC.style.top = event.y+document.body.scrollTop-dragClickY;
}
}


</script>

</head>

<body>
<script language='javascript'>CElement("123123123"); </script>
</body>
</html>



happy002 2008-11-21
  • 打赏
  • 举报
回复
function MouseMove()
{
if(Obj!=null)
{
Obj.style.left = event.x-Obj.l;
Obj.style.top = event.y-Obj.t;
}
}

你可以加alert试试,在运行event.x - Obj.l的时候 Obj.l还不存在,是undefined,当然会报错
ximizhi 2008-11-21
  • 打赏
  • 举报
回复
好长啊 帮顶!

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧