我正在制作一个无尽的卷轴。
当我按下“获取更多帖子”按钮时,添加数据后,它应该向下滚动到动态添加数据的第一个帖子(在 div 中)。
所以我想获得动态添加数据的第一个 DIV。
我试图让 jQuery 在添加的最后一个帖子之后找到 div id(这是帖子的 post_id 编号),然后让 jQuery 找到下一个最低的帖子编号(应该是动态的第一个 div id添加数据)。然后它应该向下滚动到那个。
例如:
<div id = "5">
//Post.
</div>
<div id = "4">
//Post.
</div>
//THIS IS THE DYNAMICALLY ADDED CONTENT, IT IS ONLY ADDED AFTER THE AJAX CALL WITH JQUERY.
<div id = "2"> //<--- It should scroll down to that one.
//Post.
</div>
<div id = "1">
//Post.
</div>
//Dynamically added content ends.
<script type = "text/javascript">
$(document).ready(function(){
$('#get-more-post').click(function(){
var post_id = $('div.Posted:last').attr('rel');
//In this case, the post_id = 4.
$.post("add_more_post.php", {post_id: post_id} , function(data){
if(data){
var scroll_div = //I want jQuery to find the post which is lower than post_id = 4, that is post_id = 2. How is it done?;
parent.$("html, body").animate({ scrollTop: $("div#"+scroll_div).offset().top; }, "slow");
}
});
});
});
</script>