"Object doesn’t support this property or method" when setting an object property in IE8

I’m trying to make draggable elements without using jQuery. I’d like it to be compatible with IE8. The following breaks at this.handle = { with the error, “Object doesn’t support this property or method.”

Does IE9< have some goofy hang-up when it comes to setting object properties?

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();
  }
}


Source: cross-browser

Leave a Reply