0
我試圖在不使用jQuery的情況下製作可拖動的元素。我希望它與IE8兼容。以下錯誤爲this.handle = {
,錯誤爲「對象不支持此屬性或方法」。當在IE8中設置對象屬性時,「對象不支持此屬性或方法」
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();
}
}
就是這樣。謝謝。我通過'var self = this;'解決了這個問題,我並不自豪。 – RobertAKARobin