I've been trying to get a scroll to div id jquery code to work correctly. Based on another stack overflow question i tried the following
DEMO http://jsfiddle.net/kevinPHPkevin/8tLdq/
$('#myButton').click(function() {
$.scrollTo($('#myDiv'), 1000);
});
But it didn't work. It just snaps to the div. I also tried
$('#myButton').click(function(event) {
event.preventDefault();
$.scrollTo($('#myDiv'), 1000);
});
With no progress.
You need to animate the
html, body
DEMO http://jsfiddle.net/kevinPHPkevin/8tLdq/1/
are you sure you are loading the jQuery scrollTo Plugin file?
you might be getting a object: method not found "scrollTo" error in the console.
the scrollTO method is not a native jquery method. to use it you need to include the jquery scroll To plugin file.
ref: http://flesler.blogspot.in/2009/05/jqueryscrollto-142-released.html http://flesler.blogspot.in/2007/10/jqueryscrollto.html
soln: add this in the head section.
This is the simplest.Source-https://www.w3schools.com/jsref/met_element_scrollintoview.asp
You can do it by using the following simple jQuery code.
Tutorial, Demo, and Source code can be found from here - Smooth scroll to div using jQuery
JavaScript:
HTML:
Here I tried this, that work great for me.
HTML:
This works to me.
Thanks.