拖拽
html-拖拽(draggable="true")
拖拽的7个事件:
> 拖拽块.ondragstart=function(){console.log("拖拽开始");}
> 拖拽块.ondrag=function(){console.log("拖拽中");}
> 拖拽块.ondragend=function(){console.log("拖拽结束");}
> 投放区.ondragenter=function(){console.log("进入投放区");}
> 投放区.ondragover=function(){console.log("投放区移动");
//阻止默认事件发生
e.preventDefault();
}
> 投放区.ondragleave=function(){console.log("离开投放区");}
> 投放区.ondrop=function(){console.log("投放区投放");}
(后3个容易冲突,要阻止其中一些的默认事件。要ondrop起作用,需要把ondragover也运行起来。
为了不在2个区域重叠发生事件,要设置阻止事件冒泡
用js做拖拽:
>1. 要拖动需要不停获得坐标,所有需要绝对定位,用position:absolute;
2. css在body前。js在body后
3. 匿名函数
> (function fun(){
console.log(“执行匿名函数,一定要用括号把函数括起来”);
}())

浙公网安备 33010602011771号