Try like this:
$(document).ready(function () {
// Handler for .ready() called.
$('html, body').animate({
scrollTop: $('#what').offset().top
}, 'slow');
});
Question
What I'm trying to do is very simple, but i can't find any ways to do it (and i've searched!)
I want that, when the page is loaded, the page scroll to an element with a class=""
in the page.
I've seen that there are a lot of plugins, and i've tried thing like this :
$('html, body').animate({
scrollTop: $(".class").offset().top
}, 2000);
but it doesn't work :(
Solution
Try like this:
$(document).ready(function () {
// Handler for .ready() called.
$('html, body').animate({
scrollTop: $('#what').offset().top
}, 'slow');
});
OTHER TIPS
You might also want to look at scrollTo(). It's a plugin and it works nicely, lets you set scrolls to any element, percent of page, anchors. Also can setup multiple scrolls, scrolls inside child elements fairly easily.