开发者

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

开发者 https://www.devze.com 2023-04-02 19:10 出处:网络
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 scr开发者_Go百科olling is completed.

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 scr开发者_Go百科olling 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


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');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消