admin管理员组文章数量:1026989
I'm looking for a JS / React solution to count height or lines number of draggable div blocks (having different width). Height is needed to calculate the content height inside dashed border which is equal to (viewport - draggable_blocks_height).
As you can imagine, calculation should work dynamically during the window sizing / changing resolution and during dragging the blocks / removing or adding to the draggable_blocks_container.
Any ideas, concepts or similar examples? Thank you
I'm looking for a JS / React solution to count height or lines number of draggable div blocks (having different width). Height is needed to calculate the content height inside dashed border which is equal to (viewport - draggable_blocks_height).
As you can imagine, calculation should work dynamically during the window sizing / changing resolution and during dragging the blocks / removing or adding to the draggable_blocks_container.
Any ideas, concepts or similar examples? Thank you
Share Improve this question asked May 31, 2017 at 17:21 user3844198user3844198 2052 gold badges6 silver badges15 bronze badges 2-
You can place a ref on the container of the floating divs and get the height of the div via the
innerHeight
property whenever data/sizes change. React Ref Docs. – Michael Lyons Commented May 31, 2017 at 17:26 -
innerHeight
can be used fordocument.window
. Other DOM elements haveclientHeight
stackoverflow./questions/22675126/… – pscl Commented May 31, 2017 at 19:37
2 Answers
Reset to default 2https://www.npmjs./package/react-height
Or go npm shopping for any number of variations.
I would assign a ref to a wrapper div. Then write a function that gets the height of the ref and run that func on window resize. Something like...
<dif ref={(div) => this.Wrapper = div}>
{/* blocks */}
</div>
function calcHeight() {
const rect = this.Wrapper.getBoundingClientRect();
return rect.height;
}
ponentDidMount() {
window.addEventListener('resize', this.calcHeight());
}
A bit confused on what you want to do, but if you want to mirror the height in another div, set the calculated height to state and then use a style prop to control the height of the 2nd div.
I'm looking for a JS / React solution to count height or lines number of draggable div blocks (having different width). Height is needed to calculate the content height inside dashed border which is equal to (viewport - draggable_blocks_height).
As you can imagine, calculation should work dynamically during the window sizing / changing resolution and during dragging the blocks / removing or adding to the draggable_blocks_container.
Any ideas, concepts or similar examples? Thank you
I'm looking for a JS / React solution to count height or lines number of draggable div blocks (having different width). Height is needed to calculate the content height inside dashed border which is equal to (viewport - draggable_blocks_height).
As you can imagine, calculation should work dynamically during the window sizing / changing resolution and during dragging the blocks / removing or adding to the draggable_blocks_container.
Any ideas, concepts or similar examples? Thank you
Share Improve this question asked May 31, 2017 at 17:21 user3844198user3844198 2052 gold badges6 silver badges15 bronze badges 2-
You can place a ref on the container of the floating divs and get the height of the div via the
innerHeight
property whenever data/sizes change. React Ref Docs. – Michael Lyons Commented May 31, 2017 at 17:26 -
innerHeight
can be used fordocument.window
. Other DOM elements haveclientHeight
stackoverflow./questions/22675126/… – pscl Commented May 31, 2017 at 19:37
2 Answers
Reset to default 2https://www.npmjs./package/react-height
Or go npm shopping for any number of variations.
I would assign a ref to a wrapper div. Then write a function that gets the height of the ref and run that func on window resize. Something like...
<dif ref={(div) => this.Wrapper = div}>
{/* blocks */}
</div>
function calcHeight() {
const rect = this.Wrapper.getBoundingClientRect();
return rect.height;
}
ponentDidMount() {
window.addEventListener('resize', this.calcHeight());
}
A bit confused on what you want to do, but if you want to mirror the height in another div, set the calculated height to state and then use a style prop to control the height of the 2nd div.
本文标签: javascriptJSReactcalculate height of dynamically created area with div blocksStack Overflow
版权声明:本文标题:javascript - JS, React - calculate height of dynamically created area with div blocks - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1744589312a2105400.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论