Joined April 2012
·

Tom Marshall

UK
·
·
·

Posted to Simple slideTo using jQuery over 1 year ago

You can detect anchor links using the selector, meaning you don't have to handle the alternate course (normal link) within the handler function.

In addition, delegating the 'a[href^=#]' means that any anchor links that are loaded later will also slide.

$('body').on('click', 'a[href^=#]', function (evt) {

      var $anchor = $(this).attr("href");

      $('html,body').animate({
        scrollTop: $($anchor).offset().top
      }, 1500, 'easeInOutExpo');

      evt.preventDefault();
});
Achievements
20 Karma
0 Total ProTip Views