Aero Wang
Aero Wang

Reputation: 9217

Detecting scrolling position within a scrollable element

we usually use $(window).scrollTop() to detect how far the page has been scrolled. Is there a equivalent for scrollable elements?

Say I set html to overflow hidden, and body to overflow scroll, now I want to detect $('body').scrollTop() I will always get 0.

P.S. this is useful for mobile site development.

Here is a plunker:

http://embed.plnkr.co/jZH3zCiMSfk5bIZIoDEp/

Upvotes: 1

Views: 164

Answers (2)

James Wayne
James Wayne

Reputation: 1912

Common issue with Angular. Instead of making the body scrollable, you should wrap everything inside a div and make the div an Angular controller. Then use the ng-scroll to detect scrolling position.

Upvotes: 1

Bluety
Bluety

Reputation: 1909

I think you want to get top offset of an element.

Like so with jQuery

  $('body').offset().top 

Upvotes: 0

Related Questions