借占位符实现滚动到列表底部重新加载数据_html/css_WEB-ITnose
滚动到底部更新数据是个很常见的需求,也是网站优化的一部分。
- 页面效果
pic1.png
- 第一次滚动到底部新加载数据
pic2.png
- 再滚动
pic3.png
-
源代码
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style> li{width: 100px;height: 100px;background: #000;margin-bottom: 15px;color: #fff;text-align: center;} </style> <script src="./jquery.min.js"></script></head><body> <ul class="ul-wrap"> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> <li>1</li> </ul> <div id="loadInfo"></div> <script> function randomColor(){ var color="#"; var colorArr=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]; for(i=0;i<6;i++){ var cur=randomNum(15,0); color+=colorArr[cur]; } function randomNum(max,min){ return Math.floor(Math.random()*(max-min+1)+min) } return color; } //获取滚动高度、文档高度、浏览器视口高度 var heightFuns=function(){ //获取滚动高度 heightFuns.prototype.getScrollTop=function (){ var scrollTop=0,bodyScrollTop=0,documentScrollTop=0; if(document.body){ bodyScrollTop=document.body.scrollTop; } if(document.documentElement){ documentScrollTop=document.documentElement.scrollTop; } scrollTop = (bodyScrollTop-documentScrollTop>0)?bodyScrollTop:documentScrollTop; return scrollTop; } //获取文档的总高度 heightFuns.prototype.getScrollHeight=function (){ var scrollHeight=0,bodyScrollHeight=0,documentScrollHeight; if(document.body){ bodyScrollHeight=document.body.scrollHeight; } if(document.documentElement){ documentScrollHeight=document.documentElement.scrollHeight; } scrollHeight=(bodyScrollHeight-documentScrollHeight>0)?bodyScrollHeight:documentScrollHeight; return scrollHeight; } //获取浏览器视口的高度 heightFuns.prototype.getWindowHeight=function (){ var windowHeight=0; if(document.compatMode == 'CSS1Compat'){ windowHeight=document.documentElement.clientHeight; }else{ windowHeight=document.body.clientHeight; } return windowHeight; } } function showData(){ $(".ul-wrap").append("<li>new</li>"); $("body").css("background",randomColor()); $("#loadInfo").html(""); } $(function(){ var heightObj=new heightFuns(); window.onscroll=function(){ if(heightObj.getScrollTop()==heightObj.getScrollHeight()-heightObj.getWindowHeight()){ // setTimeout(showData,1000); showData(); $("#loadInfo").html("正在加载..."); } } }); </script></body></html>
登录后复制

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

HTML适合初学者学习,因为它简单易学且能快速看到成果。1)HTML的学习曲线平缓,易于上手。2)只需掌握基本标签即可开始创建网页。3)灵活性高,可与CSS和JavaScript结合使用。4)丰富的学习资源和现代工具支持学习过程。

HTML定义网页结构,CSS负责样式和布局,JavaScript赋予动态交互。三者在网页开发中各司其职,共同构建丰富多彩的网站。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

GiteePages静态网站部署失败:404错误排查与解决在使用Gitee...

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。

实现图片点击后周围图片散开并放大效果许多网页设计中,需要实现一种交互效果:点击某张图片,使其周围的...

HTML、CSS和JavaScript是Web开发的三大支柱。1.HTML定义网页结构,使用标签如、等。2.CSS控制网页样式,使用选择器和属性如color、font-size等。3.JavaScript实现动态效果和交互,通过事件监听和DOM操作。

网页批注功能的Y轴位置自适应算法本文将探讨如何实现类似Word文档的批注功能,特别是如何处理批注之间的间�...
