Inconsistent offsetHeight behaviour as page renders

68 views Asked by At

I'm facing a problem with the offsetHeight property in JavaScript.

It returns different values every page reload.

I tried to use setTimeout and it works only sometimes. I noticed that incrementing the time to execute the function the error disappears, but this seems to be aleatory.

For debugging I tried to log the value in 3 different ways:

console.log(content.offsetHeight);
setTimeout(() => {console.log(content.offsetHeight)});
setTimeout(() => {console.log(content.offsetHeight)}, 1000);

The output can be: 493 493 644 or 493 644 644

Depending on render time. Do you have suggestions?

Thanks for help

0

There are 0 answers