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.
one example more:
HTML link:
JS:
HTML anchor:
This script is a improvement of the script from Vector. I have made a little change to it. So this script works for every link with the class page-scroll in it.
At first without easing:
For easing you will need Jquery UI:
Add this to the script:
Final
All the easings you can find here: Cheat Sheet.
If you want to override standard href-id navigation on page without change HTML markup for smooth scrolling, use this (example):
here is my 2 cents:
Javascript:
Html:
and the target:
Here's what I use:
The beauty with this one is you can use an unlimited number of hash-links and corresponding ids without having to execute a new script for each.
If you’re using WordPress, insert the code in your theme’s
footer.php
file right before the closing body tag</body>
.If you have no access to the theme files, you can embed the code right inside the post/page editor (you must be editing the post in Text mode) or on a Text widget that will load up on all pages.
If you’re using any other CMS or just HTML, you can insert the code in a section that loads up on all pages right before the closing body tag
</body>
.If you need more details on this, check out my quick post here: jQuery smooth scroll to id
Hope that helps, and let me know if you have questions about it.