Last Updated: February 25, 2016
·
518
· garik

scrollTo js snippet

Use ".scroll-to" class to enable scrolling.
Target id should be in ".scroll-to" href.

Use "data-scrollDuration" to customise duration.
If you need an offset, just add "data-scrollOffset" value to the target element.

function ik_scrollTo() {
    $(".scroll-to").click(function(e) {
        e.preventDefault();
        var href = $(this).attr("href"),
        duration = $(this).data("scrollDuration") ? $(this).data("scrollDuration") : 0,
        target = $(href),
        offest = target.data("scrollOffset") ? target.data("scrollOffset") : 0,
        o = target.offset().top - offset;

       $("html, body").animate({
            scrollTop: o
        }, duration);
    });
}