Reputation: 28138
I've tried to implement this on my site but it simply does not work. Anyone know where I'm going wrong?
Site with jQuery code included but nothing happening
Upvotes: 0
Views: 798
Reputation: 14747
This is the code provided by the smooth scrolling tutorial:
jQuery(document).ready(function($) {
$(".scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
});
});
This is the code on your page:
$('html,body').animate({scrollTop:$('[name="'+this.hash.substring(1)+'"]').offset().top}, 500);
The code you are using is the alternative the tutorial provides when using named anchors. However, that is meant the replace the corresponding part of the original code. I believe what you should have is this:
jQuery(document).ready(function($) {
$(".scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollTop:$('[name="'+this.hash.substring(1)+'"]').offset().top}, 500);
});
});
Upvotes: 3