javascript - 滚动时加载内容

标签 javascript jquery html css

我有下面的html表格

<table id="label" style="width: 100%;">
	<tr id="tr">
		<td class='td'>
			<div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>The Internet connection has</strong></div>
			<iframe src="http://www.youtube.com/embed/w9DTUjrPTd0?wmode=opaque" frameborder="0" allowfullscreen  width="100%" height="100%" ></iframe>
		</td>
		<td class='td'>
			<div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Arsenal vs man city <br> 3-2 <br>	23/5/215 <br> أرسنال ضد مانشيستر سيتي</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/aDBDowU_lqc?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
	</tr>
	<tr id="tr">
		<td class='td'>

			<div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Communications' second year</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
		<td class='td'>
			<div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Hello World</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
	</tr>
	<tr id="tr">
		<td class='td'><div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Hello World</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
		<td class='td'><div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Hello World</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
	</tr>
	<tr id="tr">
		<td class='td'><div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Hello World</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
		<td class='td'><div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Hello World</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
	</tr>
	<tr id="tr">
		<td class='td'><div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Hello World</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
		<td class='td'><div  class="layout" style="position: absolute;  z-index: 1; width: 485px; height: 280px; " onclick="this.style.display='none';"><strong>Hello World</strong></div>
			<iframe width="100%" height="100%" src="https://www.youtube.com/embed/ToACE9BTSCA?wmode=opaque" frameborder="0" allowfullscreen></iframe>
		</td>
	</tr>
</table>

我不想一次渲染所有行。我一次只需要显示 10 行,当用户滚动时,垂直滚动条又需要在现有的 10 行中再添加 10 行,依此类推。

基本上我有所有静态 html 行,我需要渲染一些然后在滚动时添加更多。我该怎么做?

最佳答案

嗯,因为它是一个静态页面,我认为你可以显示前 10 行并隐藏其他行。然后使用 JS/Jquery,你需要检查你的滚动条是否到达页面底部。你可以使用这样的东西:

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       alert("bottom!");
       //shows the next 10 rows here
   }
});

关于javascript - 滚动时加载内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30553383/

相关文章:

javascript - 如何通过javascript获取元素宽度

javascript - 如何从元素中删除诸如 之类的内容?

javascript - 如何从浏览器的检查元素中隐藏视频 src 属性?

javascript - 从纬度和经度生成谷歌地图

javascript - 将项目添加到数组 React 时删除占位符

javascript - 动态灵活的网格布局

javascript - 如何使用 jQuery 滚动到我的单个页面的顶部?

javascript - 使用对象创建 D3 条形图

javascript - 带有移动平均线的 HTML5/JS 图表

javascript - 用JavaScript控制CSS3关键帧动画