IE无效参数因为vars等于NaN

时间:2017-03-24 17:47:01

标签: javascript internet-explorer invalid-argument

倒数第二行在IE11中出现“无效参数”错误 - 其他浏览器可以正常运行代码。

var active = $('.interactivemap-minimap-active', this.el);

if (x === undefined) x = self.x;
if (y === undefined) y = self.y;

var width = Math.round(self.container.width() / self.contentWidth / self.scale * this.el.width()),
height = Math.round(self.container.height() / self.contentHeight / self.scale * this.el.height()),
top = Math.round(-y / self.contentHeight / self.scale * this.el.height()),
left = Math.round(-x / self.contentWidth / self.scale * this.el.width()),
right = left + width,
bottom = top + height;

console.log("pass2: width=" + width + ", height=" + height + ", top=" + top + ", left=" + left + ", right=" + right + ", bottom=" + bottom);

active.each(function() {
$(this)[0].style.clip = 'rect(' + top + 'px, ' + right + 'px, ' + bottom + 'px, ' + left + 'px)';
});

console.log将显示:

  

宽度= Nan,高度= Nan,top = Nan,left = Nan,right = Nan,bottom = Nan

如果我注释掉麻烦的​​行,console.log将显示:

  

宽度= Nan,高度= Nan,top = Nan,left = Nan,right = Nan,bottom = Nan

     

width = 140,height = 162,top = -1,left = 0,right = 140,bottom = 161

所以看起来需要花一点时间用实际数据填充这些变量,但是当它仍然等于Nan然后是错误时它会启动最后一个函数。

有没有办法解决这个问题?

0 个答案:

没有答案