jQuery实现页面滚动图片按需加载(转载)
来源:互联网 发布:影视公司 知乎 编辑:程序博客网 时间:2024/06/06 01:06
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <title>jquery scrolling</title> <link rel="stylesheet" href="css/style.css"/></head><body> <!--imgbox--> <div class="wrapper"> <div class="img-box"> <img src="img/1.png" /> </div> <div class="img-box"> <img src="img/2.png" /> </div> <div class="img-box"> <img src="img/3.png" /> </div> <div class="img-box"> <img data-url="img/4.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/5.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/6.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/7.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/8.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/9.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/10.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/11.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/12.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/13.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/14.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/15.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/16.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/17.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/18.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/19.png" src="img/pix.png" /> </div> <div class="img-box"> <img data-url="img/20.png" src="img/pix.png" /> </div> </div> <script src="js/jquery_1.9.js"></script> <script src="js/main.js"></script></body></html>
*{ margin: 0; padding: 0;}/*wrapper*/.wrapper{ width: 500px; height: 5000px; margin: auto;}.img-box{ width: 100%; margin-bottom: 20px; padding-bottom: 10px; height: 260px; text-align: center; border-bottom: 2px dashed #ccc;}
$(function(){ var $wd = $(window), $img = $('img'), imgTop, //图片距离顶部高度 scTop, //滚动条高度 wH; //窗口高度 wH = $wd.height(); //获得可视浏览器的高度 $wd.scroll( function() { scTop = $wd.scrollTop(); //获取滚动条到顶部的垂直高度 $img.each(function(){ imgTop = $(this).offset().top; if(imgTop - wH < scTop && //图片必须出现在窗口底部上面 imgTop - wH > 0 && //排除首页图片 $(this).attr('src') != $(this).data('url')){ //排除已经加载过的图片 $(this).attr({ src: $(this).data('url') }); } }); });});
原文链接:https://my.oschina.net/leipeng/blog/221911
0 0
- jQuery实现页面滚动图片按需加载(转载)
- jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现
- jQuery 实现图片滚动加载()
- JavaScript实现 页面滚动图片加载
- JavaScript实现 页面滚动图片加载
- JavaScript实现 页面滚动图片加载
- jquery.scrollLoading实现图片滚动加载
- jQuery--页面图片等元素滚动动态加载技术
- 关于用jquery.masonry.js实现动态加载效果(当页面滚动条拉到底部时时重新加载图片)
- jQuery实现滚动加载
- JQuery页面随滚动条动态加载效果实现
- 【C#工具类】FTP--自定义FTPFactory(上传下载)
- 一天一条Linux指令-rz
- 安卓高级 Android图片缓存之初识Glide
- git杂记:忽略ssl认证
- 论初中补习班送礼乱象--制度设计
- jQuery实现页面滚动图片按需加载(转载)
- 对第三方社会化 sdk 的集成和二次封装,比如第三方授权登录、第三方分享等
- 知识点记录-2016.11.7
- 网络通信协议TCP
- 运放输入的共模输入阻抗,差模输入电阻
- 网页弹窗广告(网页每天首次打开弹出广告,此后刷新不再显示)
- 关于 @SuppressWarnings({"unchecked"})
- selenium常见问题(二)
- SQL大全