Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JQuery .scroll() to replicate a momentum based scroll panel that snaps to elements

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

like image 200
RIK Avatar asked Sep 05 '11 12:09

RIK


People also ask

What is scroll in jQuery?

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.

How do you scroll to an element in HTML?

Definition and Usage. The scrollIntoView() method scrolls an element into the visible area of the browser window.

How do I scroll down to a div?

The scrollIntoView method: The scrollIntoView() is used to scroll to the specified element in the browser. Example: Using scrollIntoView() to scroll to an element.


1 Answers

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');
});
like image 143
Peled Roy Avatar answered Sep 18 '22 03:09

Peled Roy