Reputation: 23
So the html file for this challenge doesn't have any mark-ups, but the mission is to have the screen scroll down to each section when you click on each li. Anybody know how to scroll to different section using jquery, without any plug ins?
Upvotes: 1
Views: 365
Reputation: 185
try this
$('.list li').on('click', function() {
var tabIndex = $(this).index();
$('body').scrollTop( $('section').eq(tabIndex).offset().top );
});
DEMO - http://jsfiddle.net/R5PXH/481/
Upvotes: 1
Reputation: 780
try this:
function goToAnchor(anchorID) {
$(document).scrollTop( $(anchorID).offset().top );
});
and to use it:
goToAnchor('#section-id');
Upvotes: 0