Javascript 滚动到页面底部,重新加载,然后重复
我已经检查了所有可能与此相关的问题,但我似乎找不到任何适合我的情况,要么答案不好,要么不完整 在我的例子中,我有一个Javascript 滚动到页面底部,重新加载,然后重复,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我已经检查了所有可能与此相关的问题,但我似乎找不到任何适合我的情况,要么答案不好,要么不完整 在我的例子中,我有一个html页面,其中包含一些php,显示比赛结果。由于比赛是实时的,带有结果的页面应该滚动到页面底部,然后页面应该刷新(以便可能的新分数出现),然后重复一次又一次。解决我的问题最好的办法是什么 页面大小/长度将随着更多数据进入结果页面上的表格而增加 图片: 编辑: 此代码现在滚动到页面底部,然后跳回顶部并重复,这正是我想要的,但我希望每次触底时都有一个页面刷新,然后再跳到顶部 $(f
html
页面,其中包含一些php
,显示比赛结果。由于比赛是实时的,带有结果的页面应该滚动到页面底部,然后页面应该刷新(以便可能的新分数出现),然后重复一次又一次。解决我的问题最好的办法是什么
页面大小/长度将随着更多数据进入结果页面上的表格而增加
图片:
编辑:
此代码现在滚动到页面底部,然后跳回顶部并重复,这正是我想要的,但我希望每次触底时都有一个页面刷新,然后再跳到顶部
$(function() {
var pageScan = {
speed : 10000,
loop : true,
delayRestart : 1000,
start : function(){
pageHeight = $('body').height() - window.innerHeight;
pageScan.proc(pageHeight);
},
proc : function(to){
$("body").animate(
{scrollTop: to},
pageScan.speed,
"linear",
function(){
if (pageScan.loop) {
setTimeout(function() {
window.scrollTo(0, 0);
pageScan.start();
}, pageScan.delayRestart);
}
});
}
};
pageScan.start();
});
您可以向页面添加一些JavaScript:
<script>
window.scrollTo(0,document.body.scrollHeight);
setTimeout(function (){location.reload()},5000);
</script>
scrollTo(0,document.body.scrollHeight);
setTimeout(函数(){location.reload()},5000);
这可能就是您想要的:
// Test data, ignore
for(i = 1; i < 21; i++) {
$('#results').append('<p>Test Result No.' + i + '</p>');
}
// Check every second (for example) if there is new data
// In this example there is always data
window.setInterval(function(){
update_results();
}, 1000);
// Check for new results
function update_results() {
$.ajax({
type: 'POST',
// Test data, ignore
data: {
html: 'new result'
},
// your ajax.php file
url: '/echo/html/',
success: function(data) {
// Append new results to $('#results');
// You might want to give back an array and loop through it with $.each(data, function() {});
// you might also want to check for "false" if there are no new results
$('#results').append('<p>' + data + '</p>');
// Scroll to bottom smoothly
$('html, body').animate({ scrollTop: $(document).height() }, 'slow');
}
});
}
考虑到$scores是您数据库中可能有的分数数组。现在是2016年,请使用AJAX。。角度等。假设你有一个高度为900px的页面,你想滚动到底部,现在重新加载页面,页面的高度增加,假设到1300px,现在你想继续从900滚动到1300,或者从顶部开始,即0-1300??我想再次从顶部滚动到底部。@Reddy
location.reload()代码>,请参阅,查看控制台,查看页面在跳转到顶部之前是否重新加载。找到了类似的解决方案,但您的解决方案看起来要好得多@WcPcI不想以这种方式更新结果,我只想在触底时刷新页面@WcPc
echo json_encode($scores);