lukehaas / Scrollify

A jQuery plugin that assists scrolling and snaps to sections.
MIT License
1.81k stars 577 forks source link

Support Velocity for scroll animation #108

Open drewbaker opened 8 years ago

drewbaker commented 8 years ago

I patched this to work with Velocity for the scroll animations. Makes it more smoother!

Replace these lines: https://github.com/lukehaas/Scrollify/blob/master/jquery.scrollify.js#L501-L505

        function interstitialScroll(pos) {

            if( jQuery().velocity ) {
                // Animate using Velocity!
                $(settings.target).stop().velocity('scroll', {
                    duration: settings.scrollSpeed,
                    easing: settings.easing,
                    offset: pos,
                    mobileHA: false
                });
            } else {
                // Fallback to jQuery animate
                $(settings.target).stop().animate({
                    scrollTop: pos
                }, settings.scrollSpeed,settings.easing);
            }
        }

And then replace these lines: https://github.com/lukehaas/Scrollify/blob/master/jquery.scrollify.js#L127-L129

                if( jQuery().velocity ) {
                    // Animate using Velocity!
                    $(settings.target).stop().velocity('scroll', {
                        duration: settings.scrollSpeed,
                        easing: settings.easing,
                        offset: heights[index],
                        mobileHA: false
                    });
                } else {
                    // Fallback to jQuery animation
                    $(settings.target).stop().animate({
                        scrollTop: heights[index]
                    }, settings.scrollSpeed,settings.easing);
                }
lukehaas commented 8 years ago

Thanks, I've added this to the latest version of Scrollify.

drewbaker commented 8 years ago

Cool! You should make a note in the readme that it supports Velocity.

shrpne commented 8 years ago

Since jquery3 uses requestAnimationFrame for animations, is velocity('scroll') still more efficient than $.animate('scrollTop') ? If they are equal now, i think this should not be implimented

TiagoBAndrade commented 8 years ago

@drewbaker , @lukehaas

Hello! Frist I would like to thank Lukehaas for the useful plugin he created! Also, if you don´t mind taking a look at the way I used the plugin, to see if I could do it better, I would appreciate it. link: http://tiagoandrade.eu/alumi-2/#

Now, I wanted to know how can I make sure if the plugin is using velocity. j's?