IMUXIxD
IMUXIxD

Reputation: 1227

how can I tell when the scroll-bar is at a certain height?

How can I tell when the scroll bar is at a certain height meaning when there is a certain amount of space between the top of the scroll-bar and the top of the scroll-bar's track?

And then execute JQuery code if that is a certain value.

Let's say when the space between the scroll-bar's too and the scroll-bar's track's top is 50% of the current viewport height then alert that "50% has been reached".

Upvotes: 0

Views: 52

Answers (1)

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28588

element is particular div, tag or body you want to check.

element.scrollTop - is the pixels hidden in top due to the scroll. With no scroll its value is 0.

element.scrollHeight - is the pixels of the whole div.

element.clientHeight - is the pixels that you see in your browser.

var a  =  element.scrollTop  ;

will be the position.

var b  =  element.scrollHeight - element.clientHeight  ;

will be the maximum value for scrollTop.

var c  =  (a / b)*100  ;

will be the percent of scroll [from 0 to 100].

Upvotes: 1

Related Questions