Smooth Scroll in a Website With a Small Javascript Code

Go fast in your desire section in a web page

If you want to add smooth scroll in your website something like as, you can add the Javascript code in your website.

Linking To Specific Points on a Page
When we want to link to a specific point on a page, the standard tool that HTML provides is the named anchor. Here's how that works:
  • At the destination point (e.g. a Contact form at the bottom of the page), we add a named anchor tag at the start of the section:
    <a name="contact"></a> 
    This is an invisible element that doesn't appear to visitors in the browser.
  • To link to this point (e.g. from the top of the page), we link using the hash character (#) and the name of the destination anchor:
    <a href="#contact">Go To Contact Form</a>

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


View Demo.


By- Mofizul Islam
http://themepack.net


একটি মন্তব্য পোস্ট করুন

নবীনতর পূর্বতন

যোগাযোগ ফর্ম