Smooth Scroll of window to a div using jquery

smooth scroll

if you want to scroll the window smoothly on click then you can make that using  this code to reach the particular div.

jQuery(".addto_cart_button").click(function() {
jQuery('html, body').animate({
scrollTop: jQuery("#cust-id").offset().top
}, 2000);
});

 

If you have multiple link to scroll.. like links in Navbar menu then you can use this script..

This is best for One page website ..

jQuery(".menu-item-type-custom a").click(function() {
var idd = jQuery(this).attr('href').replace( "/", "" );
jQuery('html, body').animate({
scrollTop: jQuery(idd).offset().top
}, 1000);
});

 
If in your anchor tag menu have value without slash(/)   <a href=”#about”>About</a> then use this..
var idd = jQuery(this).attr('href');

 
If have value with slash(/) <a href=”/#about”>About</a> then use this..
var idd = jQuery(this).attr('href').replace( "/", "" );

 

If this help you then.. Can you buy a Cup of Coffee for me by nst webcreation paypal--OR-- nst webcreation blog coffee cup

Published by

NST

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Chat