admin管理员组文章数量:1431788
When I observe the scroll height in my project in two different ways, two different numbers come up.
I'm currently working on a project, and i am trying to apply a background to a menu element when it is opened. Because the element can be dynamic in size, i am trying to grab the elements scroll height and trying to apply it to the background's height.
The issue is that the scroll height comes up short. When inspecting the element itself with a console log and checking its properties, the scroll height is for example 450. When I dump out the scroll height by itself, it changes to 270.
Showing the JavaScript Results of the first console log Results of the second console log
First Screenshot ("Showing the JavaScript")
console.log(subnav)
console.log("Scrollheight is: " + subnav.scrollHeight)
Second Screenshot ("Results of the first console log")
parentElement: <li class
parentNode: <li class="e
part DOMTokenList []
popover: null
prefix: null
previousElementSibling:
previousSibling: #text "
role: null
scrollHeight: 450
scrollLeft: 0
scrollLeftMax: 0
scrollTop: 0
scrollTopMax: 0
scrollWidth: 268
shadowRoot: null
slot: ""
spellcheck: false
style: CSS"Properties(0)
tabIndex: -1
Third Screenshot ("Result of the second console log")
[vite] connecting...
[vite] connected.
<div class="header__subnav-container...inter-events-none w-max">
Scrollheight is: 270
本文标签: htmlJavascript scrollHeight changes when observing the scrollHeight differentlyStack Overflow
版权声明:本文标题:html - Javascript scrollHeight changes when observing the scrollHeight differently - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745559646a2663394.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论