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);
});
}
Written by Igor Krasilnikov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Js
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#