5

The following code I have used to apply smooth scrolling between menu links and content row containers. This seems to be working fine on all browsers except for Safari.

I understand I need to define 'html' and 'body' within the offset line, however, I am not sure if I have done this correctly. Would appreciate some help on this! Thanks.

$(function() {
  $('a[href*="#"]:not([href="#"])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html, body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

0 Answers0