JavaScript Get the calculated position in pixels of a background image

I've seen variation of this question on Stackoverflow that do not answer the question.

The problem is that the background image is placed using % or center, left, top, etc. But what we actually want to know is what that positioning is calculated at in pixels. I'm not asking what it is set at in the CSS, inline style or otherwise, but what the browser has calculated the position should be based upon those style settings.

In other words, if a div is 100px wide, and we tell the background image to be 10% from the left. I want javascript to return 10 pixels, not 10%.

Please no JQuery or other libraries, just pure javascript, html and DOM.

I've already looked at: https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

I would like something like this: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect ... But for background image/s.

Those functions are as far as I've got so far looking for a solution. We have also tried getting Node properties, but we're still experimenting with that.

Thanks.

Answer:1

I am trying to convert an array into a javscript object that is designed to work with input checkboxes in AngularJS. This is the input array that I get from my backend: let selectedRolesDB = ['ADMIN'...

I am trying to convert an array into a javscript object that is designed to work with input checkboxes in AngularJS. This is the input array that I get from my backend: let selectedRolesDB = ['ADMIN'...

Facing a very silly issue. I am showing alert message on a button click. It works perfectly at first click but then it is not working on next clicks, Here is my code : http://jsfiddle.net/nre6fbm5/ ...

Facing a very silly issue. I am showing alert message on a button click. It works perfectly at first click but then it is not working on next clicks, Here is my code : http://jsfiddle.net/nre6fbm5/ ...

  1. bootstrap alert not working
  2. bootstrap alert close not working
  3. bootstrap alert dismiss not working
  4. bootstrap alert-error not working
  5. bootstrap alert class not working
  6. bootstrap alert fade not working
  7. bootstrap alert css not working
  8. bootstrap alert show not working
  9. bootstrap alert close button not working
  10. react bootstrap alert not working
  11. bootstrap 4 alert not working
  12. bootstrap alert data-dismiss not working
  13. bootstrap alert message close not working

i am very new to coding so please be gentle. i have been given a project by a college that i am studying at. to build an online interactive tutorial, very much in the same vane as codecademy and the ...

i am very new to coding so please be gentle. i have been given a project by a college that i am studying at. to build an online interactive tutorial, very much in the same vane as codecademy and the ...

  1. make html editor javascript
  2. make html editor

text content of bootstrap modal body flows outside. when long text without any space. I need a solution.text content should not overlapping when text is long <script src="https://ajax....

text content of bootstrap modal body flows outside. when long text without any space. I need a solution.text content should not overlapping when text is long <script src="https://ajax....

  1. text content bootstrap
  2. text content center bootstrap
  3. carousel with text content bootstrap
  4. bootstrap text content scroll