Questions tagged [getboundingclientrect]

For Javascript or HTML questions that use Element.getBoundingClientRect().

148 questions
5
votes
0 answers

SVG path's stroke-width affecting getBoundingClientRect() results in Firefox

The implementation of getBoundingClientRect() varies from browser to browser when it comes to a SVG path with a given stroke width, with browsers like Firefox including the stroke width (unlike Chrome, for instance). By "including the stroke width"…
user12273078
5
votes
2 answers

getBoundingClientRect from within iFrame

I have a function to assess whether an element (an iFrame) is within the viewport if the element is in view it returns true. function isElementInViewport() { var el = document.getElementById('postbid_if') var rect =…
5
votes
1 answer

How to get position of element React | Redux (.getBoundingClientRect() + .getWrappedInstance())

I am trying to find a position of a component rendered with React. I am using redux, so I had to modify the connect function to: export default connect(mapStateToProps, mapDispatchToProps,null,{ withRef: true })(MyComponent); Now I am getting a…
semyd
  • 430
  • 4
  • 17
5
votes
0 answers

Range getBoundingClientRect() top incorrect in Internet Explorer 11

I'm using a Range object and Element.getBoundingClientRect() to calculate the position of some text. I'm getting the expected result in Chrome and Firefox but in IE the top property value is wrong. To be more specific the text in contained within a…
4
votes
0 answers

How to calculate window width based on getBoundingClientRectAsync values of another element?

Is it possible to calculate viewport or window width based on getBoundingClientRectAsync values of element which is in virtual DOM? Running JS in web worker (amp-script): let button = document.querySelector('.tooltip-trigger'); async function…
4
votes
0 answers

element.getBoundingClientRect() returns wrong values in parent with grid display

Using React, I have a parent element which is div with a display grid and an input inside it.
My problen is when i remove the display:"grid" from style attribute, the…
Shahab
  • 98
  • 5
4
votes
1 answer

What unit does getBoundingClientRect return in?

I know that getBoundingClientRect() returns an object of type ClientRect or DOMRect, and each usually has properties like x, y, width, height, and more. And if you typeof those properties, you get Number. So my question is, that Number is an amount…
Lakshya Raj
  • 1,669
  • 3
  • 10
  • 34
4
votes
1 answer

How to get an element's rect BEFORE a transform?

Currently, Element.getBoundingClientRect() gives the position and dimensions of an element, but it automatically accounts for transformations via the CSS transform property. How can I get the rectangle without the transformation? In the example…
darrylyeo
  • 3,103
  • 20
  • 30
3
votes
0 answers

Get current position when changing from position "sticky" to "relative" and set that value to translate

I am cloning this website https://www.lifeatspotify.com/ and I am about 90% done, but I am having trouble with the second section "folder flips". I have made the heading stack on each other but when the third heading stacks on top all the links…
3
votes
1 answer

getBoundingClientRect() returns inaccurate values for complex SVG's in Chrome

I'm trying to calculate the bounding box of transformed SVG elements and for that I'm using getBoundingClientRect() and mapping the x and y values to SVG coordinates. However, this function seems to produce wrong outputs in Chrome and Edge when the…
3
votes
1 answer

getBoundingClientRect() returns 0 for width and height of image

Ho do I use getBoundingClientRect() to determine the width and height of image function popUp() { var img = document.createElement('img'); img.id = "TT"; img.src = "https://picsum.photos/200/300"; document.body.appendChild(img); var…
DCR
  • 14,737
  • 12
  • 52
  • 115
3
votes
2 answers

The position of the elements do not remain the same compared to their previous placed position using getBoundingClientRect

I drag and drop some elements on a div(containing background image) and upload the content . Before uploading I calculate the dropped element top,left positions wrt to parent div, so that the top,left positions can be used to place the elements…
Enthu
  • 512
  • 2
  • 13
  • 38
3
votes
2 answers

Why Range.getBoundingClientRect() returns 0 for range inside textarea?

I have