0

Using the code from https://css-tricks.com/snippets/jquery/smooth-scrolling/ and for the likes of me can't figure out why it's not working.

Script:

$('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;
    }
}
});

Website: www.soelite.net/layout/

Any ideas what it could be? The site jumps to the div container but doesn't animate.

Indo
  • 11

1 Answers1

0

See this answer: https://stackoverflow.com/a/2234749/606104

I was having this problem in safari and chrome (Mac) and discovered that .scrollTop would work on $("body") but not $("html, body")

To make it work in Safari change your script to:

$('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) {
      var bodyElement = $("html,body");
      if ($.browser.safari) { 
        bodyElement = $("body")
      }

      bodyElement.animate({
        scrollTop: target.offset().top
      }, 1000);

      return false;
    }
  }
});
Community
  • 1
  • 1
jahller
  • 2,705
  • 1
  • 28
  • 30