alicelieutier / smoothScroll

A teeny tiny smooth scroll script with ease-in-out effect and no jQuery.
MIT License
537 stars 128 forks source link

Add optional context argument #17

Closed afmklk closed 9 years ago

afmklk commented 9 years ago

Added optional context argument to scroll element instead of window.

For example, let's say you have a fixed height container with a larger element inside:

<div id="container" style="height: 100px; overflow-y: scroll;">
    <div id="element" style="height: 1000px;"></div>
</div>

You can now call:

var el = document.querySelector('#element').scrollHeight;
var duration = 1000;
var callback = null;
var context = document.querySelector('#element');
smoothScroll(el, duration, callback, context);

to scroll to bottom of container.