I am trying to upgrade the standard scrollable div overflow:scroll to me a more fluid element that furthermore will snap to the elements once the scrolling is completed.
I have a theory on how to do this but need assistance.
Modern browsers and operating systems, in particular Safari have a degree of momentum in the scroll anyway. What I would like to do is make it recognise when the scrolling animation is complete and then scroll a little further to snap to the elements li within.
Preferably I would like it to scroll smoothly right to the element that it snaps to. At the moment the scroll() feature of JQuery seams only to apply to the actual user scroll not any momentum that may follow.
iScroll does a pretty good job of this, but it is very big and bulky for our requirements and not backwards or internet explorer compatible.
Any ideas how we can achieve this.
Marvellous
The scroll() is an inbuilt method in jQuery which is used to user scroll in the specified element. This method works for all scrollable elements and the browser window. Syntax: $(selector).scroll(function) Parameter: This method accepts single parameters function which is optional.
Definition and Usage. The scrollIntoView() method scrolls an element into the visible area of the browser window.
The scrollIntoView method: The scrollIntoView() is used to scroll to the specified element in the browser. Example: Using scrollIntoView() to scroll to an element.
This is actually pretty simple and can be achieved with jQuery; you can use jQuery's animate function to animate the scrolling (scrollTop), and set the easing function to easeOutElastic from this plugin http://james.padolsey.com/demos/jquery/easing/.
$('myButton').click(function() {
$('myScroll').animate({scrollTop : XX},'easeOutElastic');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With