0

I'm rebuilding a website based on previous guy. Here is the source code, it used id to jump when clicked.

<a href="#faq01">Cancel or Modify an Order</a>

click and jump to

<a name="faq01" id="faq01"></a><strong>Cancel or Modify an Order</strong></p>
<p> Please kindly contact our customer service to cancel or modify your order. However, once your order has been processed and ...</p>

Is there a simple way to make this jump smoothly? The category is extremely big but in the same format.

Darklizard
  • 377
  • 4
  • 17
  • 1
    possible duplicate of [jQuery animate scroll to ID on page load](http://stackoverflow.com/questions/6682451/jquery-animate-scroll-to-id-on-page-load) – BeNdErR Nov 14 '13 at 09:23
  • Here is the reference http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links/ – Pradeep Nov 14 '13 at 09:24

1 Answers1

0

Use this, hope it will help

$(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;
      }
    }
  });
});
sergio
  • 5,210
  • 7
  • 24
  • 46