delarge
4/20/2016 - 9:17 AM

If URL has hash - smooth scroll to it

If URL has hash - smooth scroll to it

// If URL has hash - smooth scroll to it
 
	 $(function() {

        // Retrieves the hash from URL
        var target = window.location.hash.substring(1);


        // If hash length > 0 (there is actually a hash)
        // And the #hash element exists on page
        if(target.length > 0 && $('#'+ target).size() > 0){

			//console.log('target: ' +  target);


			$(function(){
			    $('html, body').animate({
			        scrollTop: $('#' + target + '').offset().top - 140
			    }, 1000);
			    return false;
			});


        }

    });