muthu kumar
muthu kumar

Reputation: 66

window.ScrollHeight and window.ClientHeight are returning the same value in javascript

I want to calculate the scrolled percentage using javascript.But i am not able to get because of scrollHeight issue. It is not considering the hidden page size.

Code: https://codepen.io/tmuthu/pen/jOmaKMQ

Upvotes: 0

Views: 724

Answers (1)

Omar Siddiqui
Omar Siddiqui

Reputation: 1655

Replace

var topsh = document.documentElement.scrollHeight || document.body.scrollHeight;

with

var topsh = document.querySelector('.main').scrollHeight

and it'll work.

Upvotes: 1

Related Questions