js封装拖拽事件
程序员文章站
2022-06-30 19:13:24
...
function drag(elem){
var disX,disY;
addEvent(elem,"mousedown",function(){
var event=e||window.event;
disX=event.clientX-parseInt(elem.getStyle("left"));
disY=event.clientY-parseInt(elem.getStyle("top"));
addEvent(document,"mouseMove",mouseMove);
addEvent(document,"mouseUp",mouseUp);
stopBubble(event);
cancelHandler(event);
});
function mouseMove(e){
var event=e||window.event;
elem.sttyle.left=event.clientX-disX+"px";
elem.sttyle.top=event.clientY-disY+"px";
}
function mouseUp(e){
var event=e||window.event;
removeEvent(document,"mouseMove",mouseMove);
removeEvent(document,"mouseUp",mouseUp);
}
}
上一篇: 用es6实现一个promsie
下一篇: JS拖拽事件