Jsdom: 有什么方法可以获取 scrollHeight 属性?

创建于 2015-02-02  ·  4评论  ·  资料来源: jsdom/jsdom

有没有办法获得 scrollHeight 属性(https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollHeight)?

feature layout

最有用的评论

@leepowellcouk看起来您忘记将configurable: true到您的配置中。 尝试例如:

Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
  configurable: true,
  get: function() {
    return this._scrollHeight || 0;
  },
  set(val) {
    this._scrollHeight = val;
  }
});

所有4条评论

属性本身没什么大不了的,你甚至可以在created回调中自己很容易地修补它。 然而,对于将返回有用的东西的 scrollHeight 属性,jsdom 需要开始进行布局,这(至少)是一个很远的距离,如果我们甚至想开始这样做。

我只是想使用 scrollHeight 来检查 div 内是否有溢出。 可能我将不得不查看 PhantomJS/SlimerJS。 谢谢你的回答。

有没有嘲笑它? 我试过这个:

Object.defineProperties(window.HTMLElement.prototype, {
  scrollHeight: {
    get() {
      return this._scrollHeight || 0;
    },
    set(val) {
      this._scrollHeight = val;
    }
  }
});

并得到错误: Cannot redefine property: scrollHeight

@leepowellcouk看起来您忘记将configurable: true到您的配置中。 尝试例如:

Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
  configurable: true,
  get: function() {
    return this._scrollHeight || 0;
  },
  set(val) {
    this._scrollHeight = val;
  }
});
此页面是否有帮助?
0 / 5 - 0 等级

相关问题

amfio picture amfio  ·  3评论

khalyomede picture khalyomede  ·  3评论

drewish picture drewish  ·  4评论

camelaissani picture camelaissani  ·  4评论

philipwalton picture philipwalton  ·  4评论