why does body.scrollHeight automatically increase but not decrease

旧时模样 提交于 2020-08-07 06:45:22

问题


My iframe.body has a scrollHeight property which I believe is read only I don't understand how it gets set.

When I modify the iframe.body.innerHTML with some larger HTML, I notice the iframe.body.scrollHeight increases. Great! When we set $('#previewWindow').height(iframeDocument.body.scrollHeight) this means that the scrollbar is the right height for the new larger content

However....

When I modify the iframe.body.innerHTML with some smaller HTML, I notice the iframe.body.scrollHeight remains the same. NOT great! When we set $('#previewWindow').height(iframeDocument.body.scrollHeight) and this means that the scrollbar is too long and there's loads of whitespace to scroll to at the bottom of the inner content of the iframe

Why does it increase but not decrease in the same logical way? What would be the best workaround?

Thanks

来源:https://stackoverflow.com/questions/47095807/why-does-body-scrollheight-automatically-increase-but-not-decrease

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!