jQuery Smooth Scroll to ID of n HTML element

You can use following code to scroll to ID of an element in HTML document
You need to make sure the Jquery is previously included above following code

// Add Smooth scrolling to all links
jQuery(“a”).on(‘click’, function(event) {

// Make sure this.hash has a value before overriding default behavior
if (this.hash !== “”) {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
jQuery(‘html, body’).animate({
scrollTop: jQuery(hash).offset().top
}, 1000, function(){
window.location.hash = hash;
});
} // End if
});
// End Smooth Scrolling

About Hiren Kubavat

ORACLE,MYSQL.PHP,JQUERY,JAVASCRIPT,AJAX,HTML,CSS,ANGULAR2,AWS, WORDPRESS,JOOMLA,DRUPAL,CAKEPHP,LARAVEL,CODEIGNITER,MVC & CMS.
This entry was posted in jQuery. Bookmark the permalink.

Leave a comment