介绍
这期内容当中小编将会给大家带来有关使用JavaScript怎么编写一个滚动加载更多功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
vscode
指数:
& lt; ! DOCTYPE html> & lt; html  lang=癳n"祝辞 & lt; head> ,& lt; meta charset=癠TF-8"比; ,& lt; title> Title ,& lt; style> ,*{保证金:0;,填充:0;} ,li {list-style:没有;} ,body {背景:# eee;} ,.wrapper {背景:# fff;宽度:,970 px;,保证金:20 px 汽车;,填充:,15 px;} {,h2  text-align:中心;,边界底部:,1 px solid # ddd;, padding-bottom:, 20 px;} ,li {保证金:20 px 0;,边界底部:,1 px dotted # eee;, padding-bottom:, 20 px;} {,p ,行高:25 px;} ,& lt;/style> ,& lt; https://www.yisu.com/zixun/script src="/jquery-1.11.3.js "> 脚本> >头 身体<><>脚本 让页面=1;//默认是第1页 让负荷=true; 函数getNewsList(页面){ $("。页脚img)%20.attr%20("%20src%20"、"/timg.gif ") 负荷=false; $ . get("/新闻",{页面},res=> {//console.log (res) 如果(res.news.length) { 让str=" ";//客户端渲染,客户端自己通过ajax获取数据,自已渲染数据 res.news.forEach(项=> { str +=' <李>新闻列表(加载更多)> <脚本文件。写(新的日期().toLocaleString()) 脚本>
$ {item.time}
$ {item.summary}
李> ” }) $ (“ul”) .append (str) 负荷=true; 其他}{ $ (" .footer”)。html(”- - - - - - - - - - - - - - - -我是有底线的- - - - - - - - - - - - - - - - - -”) 负荷=false; } }) } getNewsList(页面);//一上来就获取第1页的数据//判断出什么时候到底部 美元(文档)。滚动(函数(){ 让圣=$(窗口).scrollTop ();//卷上去的高度 让ch=$(窗口).height ();//一屏的高度 让dh=$(文档).height ();//整个文档(整个内容)的高度 如果((圣+ ch)>=dh & &负载){//滚动到了底部 getNewsList页面(+ +) } })> 脚本 身体>