0

I have the below jQuery code, I want the scroll to animation to work when on the same page and when you click on another page.

At the moment I have the following:-

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

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

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

It is going to the section but no animation is happening.

Any help would be much appreciated!

nsilva
  • 5,184
  • 16
  • 66
  • 108
  • you mean swing animation not run? – Mohamed-Yousef Jan 28 '16 at 09:12
  • That's correct @Mohamed-Yousef – nsilva Jan 28 '16 at 09:13
  • for this animation you need to include jquery-ui It will not work with just jquery .. try to include jquery-ui and try again and let me know if it works – Mohamed-Yousef Jan 28 '16 at 09:14
  • added https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js but the animation still doesn't seem to be happening – nsilva Jan 28 '16 at 09:17
  • I will try to make a demo please wait – Mohamed-Yousef Jan 28 '16 at 09:23
  • Possible duplicate of [jquery page scroll to different page](http://stackoverflow.com/questions/9652944/jquery-page-scroll-to-different-page) – zer00ne Jan 28 '16 at 09:24
  • Ok nsliva .. as I tested .. this effects working at least with jquery 1.9.1 with jquery-ui .. to know about effects you can take a look at http://www.tutorialspoint.com/jqueryui/jqueryui_easings.htm .. and see this demo as well https://jsfiddle.net/mohamedyousef1980/vzexkLxq/ .. if you downgrade the jquery version in my demo the effect will not work as expected – Mohamed-Yousef Jan 28 '16 at 09:29

0 Answers0