getdave / Tanlinell

Boilerplate Wordpress theme for rapid development of new WP themes. Based on the great work of the _s ("Underscore") theme.
GNU General Public License v2.0
6 stars 2 forks source link

Add JS Smooth Scrolling Utility #265

Closed getdave closed 10 years ago

getdave commented 10 years ago

Add this function to the globals

/**
 * Smooth Scrolling
 * utility function for attaching simple smooth scrolling
 * to anchors with a "hash" target in their href
 */
SITE.utils.smoothScroll = (function($) {
    $(document).ready(function(){
        $('body').on("click", ".js-smooth-scroll", function(e) {
            e.preventDefault();

            var target = $( $(this).attr('href') );

            var fudgeFactor = $(this).data('scroll-fudge-factor') || 0;

            jQuery('html, body').stop().animate({
                scrollTop: target.offset().top + fudgeFactor,
                easing: "swing",
                queue: false
            }, 2000);

        });
    });
}(jQuery));
getdave commented 10 years ago

Completed in feature branch. Will close via commit.