Questions tagged [getboundingclientrect]

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

148 questions
3
votes
1 answer

getBoundingClientRect() Object properties cannot be copied

function test(o) { console.log("Object:", o); console.log("Assign test:", Object.assign({}, o)); console.log("Keys test:", Object.keys(o)); console.log("JSON test:", JSON.stringify(o)); } var el =…
7vujy0f0hy
  • 8,741
  • 1
  • 28
  • 33
3
votes
1 answer

Find closest BoundingClientRect

I have an array of ClientRect objects which I got by doing var trackedElements = $('[track]'); var trackedBounds = []; _.each(trackedBounds, function(elem) { return $(elem)[0].getBoundingClientRect(); }); What I also have is another element's…
John Fu
  • 1,812
  • 2
  • 15
  • 20
3
votes
1 answer

Issues when HTML body element is positioned 'relative'

On one of the websites, I found that body element is set position: relative and the content inside body seem to be shifted downwards by a scale of margin-top CSS value set on the topmost element in body. Why body has CSS 'position: relative' set?…
3
votes
0 answers

GetBoundingClientRect doesn't work outside the window

I am making a script that should measure distances in a post. For example, if i have three posts: Post 1: two lines of text, then the image that I want to see. Post 2: Just the image that I want to see. Post 3: The image I want to see Followed by…
2
votes
1 answer

Why is getBoundingClientRect() returning all values as zero?

I am making a popup function which creates a popup on the user's screen. Here is the code: function popup(o){ if(typeof o==="undefined")o={"width":"75%","height":"75%","html":""}; if(!o.width)o.width="75%"; …
Lakshya Raj
  • 1,669
  • 3
  • 10
  • 34
2
votes
0 answers

How to get correct caret absolute position

I am using range.getBoundingClientRect to get caret position but it gives wrong values when the end key is pressed. Currently, I have a content-editable div and a caret div:
Lorem ipsum dolor sit amet,…
Lucas Willems
  • 6,673
  • 4
  • 28
  • 45
2
votes
2 answers

getBoundingClientRect not working as expected on body after transform

$( document ).ready(function() { $('body').append('
'); $('#tester2').css({ position:'absolute', background:'blue', width: 10, height:10 }); setInterval(function(){ …
elewinso
  • 2,453
  • 5
  • 22
  • 27
2
votes
0 answers

getBoundingClientRect is not working correctly

I am making a simple drag and drop functionality using react draggable but at the same time while dragging I want to get the top,left,right,bottom axis. I am using getBoundingClientRect But this function emitting same value while element is…
Nane
  • 2,370
  • 6
  • 34
  • 74
2
votes
0 answers

Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLObjectElement': Blocked a frame with origin

I am getting this error: Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLObjectElement': Blocked a frame with origin "http://localhost:8089" from accessing a cross-origin frame.(…) when i try to access the height and…
user4883426
2
votes
4 answers

How can I get text dimensions?

This snippet gives the width of the "theDiv", which equals to the width of the page:
This is some text