Smooth scrolling issues

Yarin Chen Source

I am using this code that I took from the internet because I haven't learned jquery and js yet. For smooth scrolling for anchors on my page and when its scrolls its just scroll all the way to the bottom of the page beacuse its not long enough yet and there are some sections that are just short.

My question is how can I set end to the scroll?

    // Add smooth scrolling to all links
    $("a").on('click', function(event) {

        // Make sure this.hash has a value before overriding default behavior
        if (this.hash !== "") {
            // Prevent default anchor click behavior

            // Store hash
            var hash = this.hash;

            // Using jQuery's animate() method to add smooth page scroll
            // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
            $('html, body').animate({
                scrollTop: $(hash).offset().top
            }, 900, function(){

                // Add hash (#) to URL when done scrolling (default click behavior)
                window.location.hash = hash;
        } // End if


comments powered by Disqus