Javascript、DOM:需要找到可滚动元素内的空间
我有一个带有孩子的可滚动元素。该子项(没有预设宽度或高度)内部是一组绝对定位的元素,可以具有任意宽度、高度、左侧和顶部值。父元素能够滚动以适应查看这些绝对定位的元素,无论它们在哪里,但我无法检索此父元素内部有多少可滚动空间。我该怎么做?
作为参考,以下是我的一些 CSS:
.ruler_container {
max-width: 620px;
max-height: 400px;
overflow: auto;
}
.ruler {
position: relative;
}
.inner_elem {
position: absolute;
}
inner_elem
的宽度、高度、左侧和顶部值是任意的。
I have a scrollable element with a child. Inside this child (which has no preset width or height) are a set of absolutely positioned elements that can have arbitrary width, height, left, and top values. The parent element is able to scroll to accommodate viewing these absolutely positioned elements wherever they are, but I'm having trouble retrieving how much of this scrollable space is inside this parent. How do I do this?
For reference, here's some of my CSS:
.ruler_container {
max-width: 620px;
max-height: 400px;
overflow: auto;
}
.ruler {
position: relative;
}
.inner_elem {
position: absolute;
}
The width, height, left, and top values for inner_elem
s are arbitrary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我在深入研究 DOM 后找到了答案:scrollWidth 和scrollHeight 属性。
我的代码和 DOM 结构现在相当复杂,所以除了上述细节之外很难让这个问题更准确。
Well, I found my answer after digging through the DOM: The scrollWidth and scrollHeight attributes.
My code and DOM structure are quite complex now, so it was hard to make this question more accurate beyond the above details.