开发者

How do I scroll to the last id with jQuery

I want when I click load more button content will automatic scroll to the last id. Hmmm

Example

$(document).ready(function(){
    $("#loadmorebutton").click(function (){
        $('#loadmorebutton').html('');
    $.ajax({
        url: "loadmore.php?lastid=" + $(".postitem:last").attr("id"),
        s开发者_运维知识库uccess: function(html){
            if(html){
                $("#postswrapper").append(html);
                $('#loadmorebutton').html('Load More');
            }else{
                $('#loadmorebutton').replaceWith('No more posts to show.');
            }
        }
    });
   });
});

Live Demo. On the demo I want, after click load more window will scroll to Post no 51 by example.


On Button click, find out the window height var wh = $(window).height(); and apply it to window scrollTop $(window).scrollTop(wh) This will make whatever is on button of the page be first thing on top.


scrollTop() might be the function you might be requiring.

var height = 100;

$("#postswrapper").scrollTop(height)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜