开发者

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

开发者 https://www.devze.com 2023-02-17 08:03 出处:网络
I\'m prepending the markup retur开发者_开发百科ned after an jquery ajax() call [the success part of the code as below]

I'm prepending the markup retur开发者_开发百科ned 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?


You can use this plugin by Ariel Flesler.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消