有没有办法获得 scrollHeight 属性(https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollHeight)?
属性本身没什么大不了的,你甚至可以在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;
}
});
最有用的评论
@leepowellcouk看起来您忘记将
configurable: true
到您的配置中。 尝试例如: