// 添加事件监听
function addEvent(ele,type,handler){
if(ele.addEventListener){console.log('1')
ele.addEventListener(type,handler,false);
}
else if(ele.attachEvent){console.log('2')
ele.attachEvent('on'+type,handler);
}else{console.log('3')
ele['on'+type]=handler;
}
}
// 删除事件监听
function removeEvent(ele,type,handler){
if(ele.removeEventListener){console.log('-1')
ele.removeEventListener(type,handler,false);
}
else if(ele.detachEvent){console.log('-2')
ele.detachEvent('on'+type,handler);
}else{console.log('-3')
ele['on'+type]=handler;
}
}
//DOM2级添加事件
addEvent(drag,'mousedown',function(){
xPanel=event.clientX-panel.offsetLeft;
yPanel=event.clientY-panel.offsetTop;
addEvent(document,'mousemove',function(event){
dragPanel(event,xPanel,yPanel);
})
addEvent(document,'mouseup',function(){
removeEvent(document,'mousemove',null);
removeEvent(document,'mouseup',null);
})
})//DOM0级的
function dragDown(){
xPanel=event.clientX-panel.offsetLeft;
yPanel=event.clientY-panel.offsetTop;
document.onmousemove=function(event){
dragPanel(event,xPanel,yPanel);
}
// 释放鼠标
document.onmouseup=function(){
document.onmousemove=null;
document.onmouseup=null;
}
}
添加回答
举报
0/150
提交
取消