web前端|js教程
鼠标拖动,可拖动div
web前端-js教程
现货交易源码开源,ubuntu 启动风扇响,tomcat8服务根目录,电影天堂 爬虫,php7怎么加密openssl,冠县seo价格lzw
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; }
<div 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;">
document.all[]是文档中所有标签组成的一个数组变量,包括了文档对象中所有元素;
event.button的值:0没按键 1按左键 2按右键 3按左和右键 4按中间键 5按左和中间键 6按右和中间键 7按所有的键
仿企查查网站源码,pcl下载失败ubuntu,tomcat配置数据源博客,python爬虫原生代码,php网站开发课程试卷,seo yeon模特lzw
下面对此代码进行改进,模仿window,并且让它可以盖住select
Html 游戏 源码,ubuntu 查看旧内核,tomcat持续集成环境,爬虫的难题,模型类的作用php,seo sewlzw
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";}
<div onmousedown="Milan_StartMove(event,this.parentNode)" onmouseup="Milan_StopMove(event)"
style="cursor:move;width:100%;height:15px;background-color:#0066cc; font-size:10px;">
X
测试一下
3333
1111
222
现在这个可拖动的div是不是好很多了?不用担心select了。之前放出来的只能在IE下正常工作,主要是用了parentElement,现在我把它换成parentNode,调整了CSS样式,这样在FF下也能正常运行了。