本文实例讲述了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>
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
关于在vue-cli 打包时,抽离项目相关配置文件的问题(详细教程)
通过使用vue制作滑动堆叠组件(详细教程)
关于在react native使用fetch实现图片上传问题(详细教程)
以上就是利用jquery实现滚动到底部时自动加载的详细内容。
