1

I found this fiddle http://jsfiddle.net/tovic/kw7LD/ that shows how to apply smooth scroll to external link with class. I'd like to know if is possible apply the same effect using id instead of classes.

$(window).bind("load", function () {
var urlHash = window.location.href.split("#")[1];
$('html,body').animate({
    scrollTop: $('.' + urlHash).offset().top
}, 4000);

});

P.S. I found also this question Smooth scrolling when clicking an anchor link but the answer didn't work for me.

Community
  • 1
  • 1
Samm
  • 121
  • 3
  • 6
  • 14

1 Answers1

0

Try this:

$(document).on("ready", function () {
    var urlHash = window.location.href.split("#")[1];
    $('html,body').animate({
        scrollTop: $('.' + urlHash).offset().top
    }, 4000);
});
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
  • It didn't work. It still works only with classes no with id. Here's the fiddle: [jsfiddle.net](http://jsfiddle.net/Gvr7a/show/#section5) – Samm Apr 19 '13 at 12:21