javascript - jQuery scroll to ID script only scrolling down -
i'm using following make anchor class of .jump-link
scroll id it's referencing in href
attribute:
// scroll id $('.jump-link').click(function () { var el = $(this).attr('href'), elwrapped = $(el); scrolltoid(elwrapped, 40); return false; }); function scrolltoid(element, navheight) { var offset = element.offset(), offsettop = offset.top, totalscroll = offsettop - navheight; $('body,html').animate({ scrolltop: totalscroll }, 500); }
unfortunately though seems work scrolling down page. i'd script work scrolling page.
try this.. work.
$(".jump-link").click(function(){ var id = $(this).attr('href'); $('html, body').animate({scrolltop: $("#"+id).offset().top}, 2000); });
Comments
Post a Comment