I have an html element whose height
is set to 100vh
and value of overflow
is set to auto
. So user can scroll the element to view it. What I want is to calculate actual height of the element. I am using offsetHeight
property to calculate height. But is is giving me only 100vh
height. But what I want is the height which will be given by offsetHeight
when height
of element is set to auto
. How to calculate it when height
of the element is set to 100vh
.
Asked
Active
Viewed 217 times
-1

Mauj Mishra
- 133
- 1
- 12
-
1You look for [element.scrollHeight](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight)... – Louys Patrice Bessette Mar 07 '21 at 17:36
-
if its 100vh, then you can get the value from `window.innerHeight`, btw 100vh won't be correct in i(phone|pad), so is better to set a var and use css `var(--vh)` instead, example: https://repl.it/@lcherone/iPad-100vh-fix#index.html – Lawrence Cherone Mar 07 '21 at 17:39
1 Answers
0
I am new in this business but I use this code the calculate height of the div (whatever div that I choose It doesn't matter).
let height = document.querySelector("div").offsetHeight;
if (
document.body.scrollTop > height ||
document.documentElement.scrollTop > height
) {
//code
} else {
//code
}

ates_irem
- 286
- 1
- 8