这次给大家带来如何实现滚动条滑到底部时自动加载更多内容,实现滚动条滑到底部时自动加载更多内容的注意事项有哪些,下面就是实战案例,一起来看一下。
本文实例讲述了jquery实现滚动到底部时自动加载更多的方法。分享给大家供大家参考,具体如下:
这里利用ajax,实现滚动到底加载数据功能:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<script src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
addsth();
});
$(function () {
$(.main).unbind(scroll).bind(scroll, function (e) {
var sum = this.scrollheight;
if (sum <= $(this).scrolltop() + $(this).height()) {
addsth();
}
});
});
function addsth() {
$.ajax({
type: 'post',
url: "index.aspx/returnsth",
datatype: "json",
contenttype: "application/json; charset=utf-8",
//data: "",
success: function (data) {
json = $.parsejson(data.d);
for (var i in json) {
var tbbody = "<ul><li> + json[i].sth + </li></ul>;
$(.main).append(tbbody);
}
$(.main).append(<hr />);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<p>下拉加载更多</p><br />
<p class="main" style="border: 1px solid red; height: 700px; overflow: auto;"></p>
</form>
</body>
</html>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
如何用jquery做出放大镜效果
jquery添加带有样式的html标签
jquery怎样给动态生成的标签绑定事件
jquery怎样获取标签子元素的值
以上就是如何实现滚动条滑到底部时自动加载更多内容的详细内容。