嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元微信扫码支付:1 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
利用javascript实现物体拖拽功能
//拖拽 必须是绝对定位才能使用 position:absolute
Base.prototype.drag = function() {
for (var i = 0; i < this.elements.length; i ) {
this.elements[i].style.position = 'absolute';
this.elements[i].style.cursor = 'move';
this.elements[i].onmousedown = function (e) {
var e = getEvent(e);
var _this = this; //_this保存的是DIV
var diffX = e.clientX - _this.offsetLeft; // 当前点击位置与div水平方向边距距离
var diffY = e.clientY - _this.offsetTop; // 当前点击位置与div垂直方向边距距离
document.onmousemove = function (e) {
var e = getEvent(e);
_this.style.left = e.clientX - diffX 'px';
_this.style.top = e.clientY - diffY 'px';
}
document.onmouseup = function () {
this.onmousemove = null; //这里的this是document
this.onmouseup = null;
}
};
}
return this;
}