~~~
// 元素拖动
// dragButtonName 拖动按钮
// moveElementName 要移动的元素
function drag(dragButtonName, moveElementName) {
var moveElement = DQ(moveElementName);
DQ(dragButtonName).onmousedown = function (e) {
var x = e.layerX;
var y = e.layerY;
document.onmousemove = function (e) {
moveElement.style.left = e.pageX - x + 'px';
moveElement.style.top = e.pageY - y + 'px';
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
};
}
}
// document.querySelector
function DQ(name) {
return document.querySelector(name);
}
~~~