ptamzz
ptamzz

Reputation: 9365

jquery automated scroll on prepend() success [How to]

I'm prepending the markup returned after an jquery ajax() call [the success part of the code as below]

success: function(html){
    $("ul#lists").prepend(html);
    $("ul#lists li:first").fadeIn("slow");
}

When the prepend is success, I want the page to automatically scroll to the position where the prepend is happening. I'm not sure of the syntax but the following is something like what I want.

success: function(html){
        if($("ul#lists").prepend(html)) {
            //Scroll to the position in the page where the prepend is about to happen
            //something similar to the href="#bookmark' in html. 
        }
        $("ul#lists li:first").fadeIn("slow");
    }

So how do I do that?

Upvotes: 1

Views: 1084

Answers (2)

druveen
druveen

Reputation: 1691

Hi u can use this , were id is element id where page has to be scrolled.

$('html, body').animate({scrollTop: $("#"+id).offset().top}, 2000);

Keep laughing.

Upvotes: 1

kpower
kpower

Reputation: 3891

You can use this plugin by Ariel Flesler.

Upvotes: 3

Related Questions