创建无限页内容循环
Create an infinite page content loop
我正在尝试创建一个(笑话)网站,在加载时做以下事情:
- 开始以x速度向下滚动
- 连续加载并附加相同的内容到页面底部
- 连续滚动过去额外加载的内容,从未停止
我该怎么做呢?
点注意:
-
这里的技巧是不要在animate函数上使用默认的swing easing来使动画无缝。
-
同样,你不能简单地动画到页面的底部,而是动画到当前scrollTop的下一步。
$(function() {
// every 1 seconds, check + update
setInterval(appendContent, 800);
setInterval(continueScrolling, 1000);
});
var b = $('body');
// if almost at bottom, append more content
function appendContent() {
if($(window).scrollTop() + $(window).height()*2 > $(document).height()) {
// Load/append your new content here.
// I am doubling the content for demostration purposes.
b.html(b.html() + b.html());
}
}
// continue scrolling linearly
function continueScrolling() {
// get current scroll position
y = $(window).scrollTop();
// stop previous animation, animate to the next 1000 pixels
// to make it scroll faster, increase the constant after the y
$("html, body").stop()
.animate({ scrollTop: y+1000 }, {
duration: 1000, // you won't want to scroll too quickly
easing: 'linear', // cannot use the default 'swing' here
queue: false
});
}
演示:看到现场演示
理论上,你可以使用javascript跟踪div,因为它滚动到它的y位置,并使用jQuery加载相同的数据/html/php到附加的子div每N个像素
我想我必须试一试,看看我能想出什么。
这是我想到的,似乎在基本水平上工作
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function keepGoing(counter) {
var objTo = document.getElementById('foreverDiv')
var divtest = document.createElement("moreStuffDiv" + counter);
divtest.setAttribute("id", "moreStuffDiv" + counter);
divtest.innerHTML = "new div " + counter + "<br>";
objTo.appendChild(divtest);
document.getElementById('moreStuffDiv' + counter).scrollIntoView();
counter = counter +1;
}
jQuery(document).ready( function() {
setInterval( 'keepGoing(1)', 10 );
});
</script>
<div id="contentDiv">
<h1>Content</h1>
<div id="foreverDiv">
</div>
</div>
相关文章:
- 使用滚动溢出-x进行无限循环
- 超过了最大调用堆栈大小,循环无限
- 无限的java脚本循环
- 从index.html调用函数,该函数无限循环
- 为什么我使用javascript获得了一个无限的for循环
- 使用jQuery无限循环播放HTML页面幻灯片
- Grunt任务没有加载,获得无限循环
- 如何在不进入无限循环的情况下将网站重定向到Facebook画布URL
- Backbone+RequireJS+Mediator模式导致视图逻辑短路和无限循环
- jQuery无限循环,动画化许多项目
- 如何避免试图用php+jquery显示php起始页的无限循环
- 6502仿真增强型基本无限循环$C000至$E0ED
- Angular ngRoute导致无限循环和堆栈溢出
- Jquery:无限循环和暂停
- 数组数组:无限循环
- 为什么while循环无限循环
- 为什么我的代码循环无限提交而不回显$post-nametest_value
- 简单的 do/while 循环无限循环问题
- JavaScript For Loop保持循环无限
- 为什么这个javascript循环无限返回