富贵资源网 Design By www.hznty.com
复制代码 代码如下:
<html><head>
<title>测试可动div</title>
<script language='javascript' type='text/javascript'>
var offset_x;
var offset_y;
function Milan_StartMove(oEvent)
{
var whichButton;
if(document.all&&oEvent.button==1) whichButton=true;
else { if(oEvent.button==0)whichButton=true;}
if(whichButton)
{
var oDiv=document.getElementById("oDiv");
offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft);
offset_y=parseInt(oEvent.clientY-oDiv.offsetTop);
document.documentElement.onmousemove=function(mEvent)
{
var eEvent;
if(document.all) eEvent=event;
else{eEvent=mEvent;}
var oDiv=document.getElementById("oDiv");
var x=eEvent.clientX-offset_x;
var y=eEvent.clientY-offset_y;
oDiv.style.left=(x)+"px";
oDiv.style.top=(y)+"px";
}
}
}
function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; }
</script>
</head>
<body>
<div id="oDiv" onmousedown="Milan_StartMove(event)" onmouseup="Milan_StopMove(event)"
style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid
silver;left:100px;top:100px;z-index:9999;"></div>
</body></html>
document.all[]是文档中所有标签组成的一个数组变量,包括了文档对象中所有元素;
event.button的值:0没按键 1按左键 2按右键 3按左和右键 4按中间键 5按左和中间键 6按右和中间键 7按所有的键
下面对此代码进行改进,模仿window,并且让它可以盖住select
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试可动div</title>
<script language='javascript' type='text/javascript'>
var offset_x;
var offset_y;
function Milan_StartMove(oEvent,div_id)
{
var whichButton;
if(document.all&&oEvent.button==1) whichButton=true;
else { if(oEvent.button==0)whichButton=true;}
if(whichButton)
{
var oDiv=div_id;
offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft);
offset_y=parseInt(oEvent.clientY-oDiv.offsetTop);
document.documentElement.onmousemove=function(mEvent)
{
var eEvent;
if(document.all) eEvent=event;
else{eEvent=mEvent;}
var oDiv=div_id;
var x=eEvent.clientX-offset_x;
var y=eEvent.clientY-offset_y;
oDiv.style.left=(x)+"px";
oDiv.style.top=(y)+"px";
var d_oDiv=document.getElementById("disable_"+oDiv.id);
d_oDiv.style.left=(x)+"px";
d_oDiv.style.top=(y)+"px";
}
}
}
function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; }
function div_Close(o)
{var oDiv=o; oDiv.style.display="none";var d_oDiv=document.getElementById("disable_"+o.id);d_oDiv.style.display="none";}
</script>
</head>
<body>
<div id="oDiv" style="position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;">
<div id="move" onmousedown="Milan_StartMove(event,this.parentNode)" onmouseup="Milan_StopMove(event)"
style="cursor:move;width:100%;height:15px;background-color:#0066cc; font-size:10px;">
<div onclick="div_Close(this.parentNode.parentNode)" style="float:right; width:10px; height:100%; cursor:hand; background-color:#cc3333; color:White;font-size:15px;">X</div>
</div>
<span>测试一下</span>
</div>
<div id="disable_oDiv" style="position:absolute;left:100px;top:100px;width:100px; height:60px; z-index:9998;FILTER:alpha(opacity=50);";>
<iframe src="/UploadFiles/2021-04-02/about:blank"><select name="ListHead1$DropDownList3" id="ListHead1_DropDownList3">
<option selected="selected" value=""></option>
<option value="2">3333</option>
<option value="6">1111</option>
<option value="B">222</option>
</select>
</body>
</html>
现在这个可拖动的div是不是好很多了?不用担心select了。之前放出来的只能在IE下正常工作,主要是用了parentElement,现在我把它换成parentNode,调整了CSS样式,这样在FF下也能正常运行了。
<html><head>
<title>测试可动div</title>
<script language='javascript' type='text/javascript'>
var offset_x;
var offset_y;
function Milan_StartMove(oEvent)
{
var whichButton;
if(document.all&&oEvent.button==1) whichButton=true;
else { if(oEvent.button==0)whichButton=true;}
if(whichButton)
{
var oDiv=document.getElementById("oDiv");
offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft);
offset_y=parseInt(oEvent.clientY-oDiv.offsetTop);
document.documentElement.onmousemove=function(mEvent)
{
var eEvent;
if(document.all) eEvent=event;
else{eEvent=mEvent;}
var oDiv=document.getElementById("oDiv");
var x=eEvent.clientX-offset_x;
var y=eEvent.clientY-offset_y;
oDiv.style.left=(x)+"px";
oDiv.style.top=(y)+"px";
}
}
}
function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; }
</script>
</head>
<body>
<div id="oDiv" onmousedown="Milan_StartMove(event)" onmouseup="Milan_StopMove(event)"
style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid
silver;left:100px;top:100px;z-index:9999;"></div>
</body></html>
document.all[]是文档中所有标签组成的一个数组变量,包括了文档对象中所有元素;
event.button的值:0没按键 1按左键 2按右键 3按左和右键 4按中间键 5按左和中间键 6按右和中间键 7按所有的键
下面对此代码进行改进,模仿window,并且让它可以盖住select
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试可动div</title>
<script language='javascript' type='text/javascript'>
var offset_x;
var offset_y;
function Milan_StartMove(oEvent,div_id)
{
var whichButton;
if(document.all&&oEvent.button==1) whichButton=true;
else { if(oEvent.button==0)whichButton=true;}
if(whichButton)
{
var oDiv=div_id;
offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft);
offset_y=parseInt(oEvent.clientY-oDiv.offsetTop);
document.documentElement.onmousemove=function(mEvent)
{
var eEvent;
if(document.all) eEvent=event;
else{eEvent=mEvent;}
var oDiv=div_id;
var x=eEvent.clientX-offset_x;
var y=eEvent.clientY-offset_y;
oDiv.style.left=(x)+"px";
oDiv.style.top=(y)+"px";
var d_oDiv=document.getElementById("disable_"+oDiv.id);
d_oDiv.style.left=(x)+"px";
d_oDiv.style.top=(y)+"px";
}
}
}
function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; }
function div_Close(o)
{var oDiv=o; oDiv.style.display="none";var d_oDiv=document.getElementById("disable_"+o.id);d_oDiv.style.display="none";}
</script>
</head>
<body>
<div id="oDiv" style="position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;">
<div id="move" onmousedown="Milan_StartMove(event,this.parentNode)" onmouseup="Milan_StopMove(event)"
style="cursor:move;width:100%;height:15px;background-color:#0066cc; font-size:10px;">
<div onclick="div_Close(this.parentNode.parentNode)" style="float:right; width:10px; height:100%; cursor:hand; background-color:#cc3333; color:White;font-size:15px;">X</div>
</div>
<span>测试一下</span>
</div>
<div id="disable_oDiv" style="position:absolute;left:100px;top:100px;width:100px; height:60px; z-index:9998;FILTER:alpha(opacity=50);";>
<iframe src="/UploadFiles/2021-04-02/about:blank"><select name="ListHead1$DropDownList3" id="ListHead1_DropDownList3">
<option selected="selected" value=""></option>
<option value="2">3333</option>
<option value="6">1111</option>
<option value="B">222</option>
</select>
</body>
</html>
现在这个可拖动的div是不是好很多了?不用担心select了。之前放出来的只能在IE下正常工作,主要是用了parentElement,现在我把它换成parentNode,调整了CSS样式,这样在FF下也能正常运行了。
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。