0

jScrollPane library have a scrollToElement method which can scroll to element if it not in viewport.

Also this method have a stickToTop parameter which scroll as little as possible to show the element (not top of the viewport, like it do scrollTop).

Anyone knows standalone plugin for that functionality? Or how it can be realised in JS (I'm not an expert in JS and I can't extract this function from jScrollPane).

inetbug
  • 409
  • 6
  • 16
  • 1
    What have you tried? – Sleek Geek Jan 15 '16 at 13:11
  • 1
    There is a native js method for that but without any kind of animation: [scrollIntoView()](https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView) `Anyone knows standalone plugin for that functionality?` That kind of question doesn't fit SO rules... – A. Wolff Jan 15 '16 at 13:13
  • Possible duplicate of [How can I scroll to a specific location on the page using jquery?](http://stackoverflow.com/questions/1586341/how-can-i-scroll-to-a-specific-location-on-the-page-using-jquery) – Mr. Polywhirl Jan 15 '16 at 13:16
  • @A.Wolff actually, scrollIntoView() can be animated (look at scrollIntoViewOptions param at your own MDN link). And for browser with no support of scroll behavior there is a [polyfill](https://github.com/iamdustan/smoothscroll) – Paul Kozlovitch Jan 15 '16 at 13:19
  • @PaulKozlovitch Ya but that's a working draft, only currently supported on FF BUT good point EDIT: oops, I didn't have checked your polyfill link... :) – A. Wolff Jan 15 '16 at 13:21

1 Answers1

1

Yuu should user scrollIntoView(true) function.

https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView

inetbug
  • 409
  • 6
  • 16