Javascript jQuery自动向下滚动、暂停、再次向下滚动和向上滚动?
我有一个基本上包含一个大表的网页,我使用ajax每分钟自动创建和填充一个表。基本代码结构如下所示:Javascript jQuery自动向下滚动、暂停、再次向下滚动和向上滚动?,javascript,ajax,jquery,Javascript,Ajax,Jquery,我有一个基本上包含一个大表的网页,我使用ajax每分钟自动创建和填充一个表。基本代码结构如下所示: $(document).ready(function(){ setInterval(function(){ $.ajax({ //code to call backend, get the data, //create/populate the table, and refresh every minute })
$(document).ready(function(){
setInterval(function(){
$.ajax({
//code to call backend, get the data,
//create/populate the table, and refresh every minute
});
});
}
由于表格很长,我想让它自动向下滚动,暂停几秒钟,继续向下滚动,再次暂停。当它到达终点时,它会向上滚动,暂停……或者,当它到达终点时,从顶部开始,重新开始。当它滚动时,我还希望将它的表头行固定在顶部
我的问题是:
setInterval(function(){
$.ajax({
type : "",
dataType: "",
url : "",
data : "",
success : function(data)
{
// create/append data to table
// animate scroll to bottom of table
$("#my_table").animate({ scrollTop: $("#my_table").height() }, "slow");
}
});
});
不确定滚动代码是否100%正确,但它应该会让您开始。我在post中尝试了这种方法,但它似乎干扰了ajax,并且我的ajax功能不再工作。我使用这个jquery插件获得了很好的结果: