Anchor smooth scrolling not working on a Wordpress site

I have this smooth anchor scroll code inserted on my Wordpress site http://www.ilovestvincent.com

jQuery(function(){
    jQuery('a[href^="#"]').on('click',function (e) {

        var target = this.hash;
        var $target = jQuery(target);

        jQuery('html, body').stop().animate({
            'scrollTop': $(target).offset().top
        }, 900, 'swing', function () {
            window.location.hash = target;
        });
    });
});

This should trigger a smooth scroll when clicking the top menu links but it's not working. This code is working fine on my other sites but I'm stumped as to why it wouldn't be working on ilovestvincent.com.

Any tips would be highly appreciated, cheers.

1 answer

  • answered 2017-06-17 19:01 buxbeatz

    Here is the snippet which should work:

    jQuery(document).ready(function(){
        jQuery('a[href^="#"]').click(function() {
    
           var target = jQuery(this).attr('href');
    
           jQuery('html, body').stop().animate({
             'scrollTop': target.offset().top
           }, 900, 'swing', function () {
              window.location.hash = target;
           });
    
       });
    });