checking for scrollHeight of an element sometimes returning 0

前端 未结 2 1712
[愿得一人]
[愿得一人] 2021-01-15 16:03

So I am checking the the scrollHeight of some dynamically generated content to determine whether or not to include a more button in the content. The user can click the more

相关标签:
2条回答
  • 2021-01-15 16:39

    I would recommend looking at these (I couldn't locate a similar link for Chrome):

    MSDN: http://msdn.microsoft.com/en-us/library/ms530302%28v=VS.85%29.aspx

    MOZ: https://developer.mozilla.org/en/Determining_the_dimensions_of_elements

    It seems that scrollHeight is only valid if something is large enough to need to scroll, so I would assume that 0 means no scrolling needed (all content is visible). From looking at the above links, maybe what you want is clientHeight.

    0 讨论(0)
  • 2021-01-15 16:41

    I figured out the problem, It had to do with the what I was trying to check after different elements were set to display none. For some reason for 5-8 cells it was checking other content instead of the page I was on and then switching to the current content. Changing some Id's ultimately let me fix it.

    0 讨论(0)
提交回复
热议问题