-2

So I have the following div.

On google chrome I can inspect the element and see the size of the div. How can I capture the size of this div and store it as a variable? I'm assuming this can dynamically change depending on the users platform.

I need the current size of the div to create a ping pong type floating ball contained in the size of that div.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
Jay
  • 67
  • 9
  • This might be what you need: [https://stackoverflow.com/questions/294250/how-do-i-retrieve-an-html-elements-actual-width-and-height] – Grasshopper Oct 18 '19 at 19:31
  • Possible duplicate of [ReactJS - Get Height of an element](https://stackoverflow.com/questions/35153599/reactjs-get-height-of-an-element) – Emile Bergeron Oct 18 '19 at 20:18
  • Since you tagged the question with React, a mix of `getBoundingClientRect`, and React's refs should be enough. Se also: https://stackoverflow.com/q/49058890/1218980 – Emile Bergeron Oct 18 '19 at 20:20

1 Answers1

2

Sounds like you're looking for getBoundingClientRect, which gives you the bounding box values for any element in the DOM.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153