ES6_拖拽
<div id="box"></div>CSS:
div {
width:100px;
height:100px;
border-radius:50%;
position:absolute;
}
JS:
class Pen {
constructor() {
document.onmousedown = this.down.bind(this);
}
down() {
document.onmousemove = this.move.bind(this);
document.onmouseup = this.up.bind(this);
}
move(e) {
var e = e || event;
var div = document.getElementById("box");
div.style.cssText = "left:" + e.clientX + "px; top:" + e.clientY + "px;";
div.style.background = "blue";
}
up() {
document.onmousemove = null;
document.onmouseup = null;
}
}
new Pen();
页:
[1]