ScrollTop with jQuery and overflow div

Mark Neto picture Mark Neto · Jun 18, 2012 · Viewed 9.6k times · Source

I'm having a problem, trying to make a scrollTo within a div with overflow.

I created five sections and five links in the menu. When I click on a link from the menu, I would like it to be correct div.

The link to content that I did: http://jsbin.com/adagid/

Sometimes it appears right (when you click directly on the first or last link), but sometimes the content displayed is the middle of the content.

how I can fix this problem?

Answer

Kao Vang picture Kao Vang · Jun 18, 2012

Since the position of the section changes with each scroll, you want to use += on the property being animated.

Check this fiddle. I also changed the bind to on and instead of trying to split the class name to find the section, I used data attributes.

http://jsfiddle.net/KvQ7W/