Lucy MacGregor Lucy MacGregor - 6 months ago 14
HTML Question

Smooth Scroll for anchor links not working

I'm trying to get a smooth scroll effect for my anchor links on a clients website. For some reason the anchors stop working at all when I add the scroll code. I tried doing a pen with just a nav and the code and it worked fine, so it must be something else on my page causing the issue, help please??

http://codepen.io/anon/pen/dYegMK <-- its a bit barren but I had to delete the clients content for their privacy

(function($) { 

$(document).ready(function() {

$(function() {

$('nav#cssmenu a').bind('click', function(event) {
var $anchor = $(this);

$('html, body').stop().animate({
scrollTop: ($($anchor.attr('href')).offset().top - 95)
}, 1500, 'easeInOutExpo');
event.preventDefault();
});

}); 

});

}(jQuery));

Answer

Try to use linear and swing easing. You can find more info here Easing functions in jQuery

Comments