我有一个客户端请求静态页面将所述页面的内容滚动到底部,然后将页面内容切换到另一个php文件(它只是返回html),滚动到底部并重复。我尝试使用递归jQuery函数来完成此任务,但每次函数调用自身时,它似乎都会在循环中运行两次,或者内容几乎立即刷新。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<div id="content">
<p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p>
<p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p>
<p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p>
<p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p>
<p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p><p>This is dummy content.</p>
</div>
<script type="text/javascript">
function Slideshow (Counter) {
var Count = Counter;
var Pages = [ "slideshow/50_50.php",
"slideshow/news.php",
"slideshow/sponsorship.php",
"slideshow/standings.php",];
var time = ($(document).height()/100)*1000;
var height = $(document).height() - $(window).height();
if (height <= 0) {
height = $(window).height();
time = 5000;
}
$("html, body").animate({ scrollTop: height }, time, function() {
$("#content").load(Pages[Count], function(){
Count++;
if (Count >= 2) {
Count = 0;
}
//alert("Height: "+height+"\nTime:"+time+"\nCounter:"+Counter);
Slideshow(Count);
});
});
};
$(document).ready(function() {
Slideshow(0);
});
</script>
</body>
</html>
&#39;页面&#39; array是要返回的内容的页面列表。时间和高度是(应该是)滚动动画的计算字段,检查内容是否小于屏幕高度,内容将在屏幕上保留5秒钟。
另一组眼睛将不胜感激。
答案 0 :(得分:1)
这是问题所在:
$("html, body").animate(...
然后,每次递归调用都会调用两次Slideshow
方法,从而导致调用爆炸。尝试替换为:
$('body').first().animate(...