繁体   English   中英

在IE8中设置对象属性时出现“对象不支持此属性或方法”

[英]“Object doesn't support this property or method” when setting an object property in IE8

我正在尝试使可拖动元素不使用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();
  }
}

IE8不支持Function.prototype.bind() 您可以为此编写一个polyfill

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM