我试图在不使用jQuery的情况下制作可拖动的元素。我希望它与IE8兼容。以下内容在this.handle = {
处中断,错误为“对象不支持此属性或方法。”
IE9<在设置对象属性时有一些愚蠢的挂起?
var Draggable = function(el){
this.el = el;
this.el.style.left = "0px";
this.el.style.top = "0px";
this.origin = {};
this.handle = {
drag: this.drag.bind(this),
move: this.move.bind(this)
};
this.events = {
start: new Listener(this.el, ["mousedown", "touchstart"], this.handle.drag),
move: {},
end: {}
};
}
Draggable.prototype = {
drag: function(evt){
this.origin.left = parseInt(this.el.style.left) - evt.clientX;
this.origin.top = parseInt(this.el.style.top) - evt.clientY;
this.events.move = new Listener(window, ["mousemove", "touchmove"], this.handle.move);
this.events.end = new Listener(window, ["mouseup", "touchend"], this.drop.bind(this));
},
move: function(evt){
this.el.style.left = this.origin.left + evt.clientX + "px";
this.el.style.top = this.origin.top + evt.clientY + "px";
},
drop: function(){
this.events.move.stopListening();
}
}