Alex
Alex

Reputation: 38529

Showing / scrolling to top of page in jQuery

I'm developing an app with a kind of multiple part form (step 1, step 2 etc...)

What I'm doing, is separating this out in divs, and having the submit button hide the current div, and show the next one.

I'd like the page to scroll to the top (as if it were a postback) when hiding/showing the next part:

$('#my_submit_button').click(function (){
    $('#div_one').hide();
    $('#div_two').show();

    //now it should scroll to top of window...
    $(window).scrollTop(100);
});

However, this isn't working as expected.

Upvotes: 0

Views: 170

Answers (2)

Ghokun
Ghokun

Reputation: 3465

    $('body').animate({scrollTop : 0},'slow');

use this for the last part.

also use .hide("fast"); and .show("fast")

Upvotes: 1

Ben L
Ben L

Reputation: 2571

You could scroll to the top of your div by doing:

$('#my_submit_button').click(function (){
    $('#div_one').hide();
    $('#div_two').show();

    window.location.href = '#div_two';
});

Upvotes: 0

Related Questions