首页 > 代码库 > 延时加载图片
延时加载图片
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>css3</title><style type="text/css">*{ margin:0; padding: 0;}ul,li{ list-style: outside none none;}.box{ width: 600px; margin: 0 auto;}.box li{ margin: 40px 0; width: 100%; height: 170px; background: #ddd;}.box li img{ width: 100%;}</style></head><body><div class="box"> <ul> <li><img x-src="img/1.jpg" alt=""></li> <li><img x-src="img/2.jpg" alt=""></li> <li><img x-src="img/3.jpg" alt=""></li> <li><img x-src="img/4.jpg" alt=""></li> <li><img x-src="img/5.jpg" alt=""></li> <li><img x-src="img/1.jpg" alt=""></li> <li><img x-src="img/2.jpg" alt=""></li> <li><img x-src="img/3.jpg" alt=""></li> <li><img x-src="img/4.jpg" alt=""></li> <li><img x-src="img/5.jpg" alt=""></li> <li><img x-src="img/1.jpg" alt=""></li> <li><img x-src="img/2.jpg" alt=""></li> <li><img x-src="img/3.jpg" alt=""></li> <li><img x-src="img/4.jpg" alt=""></li> <li><img x-src="img/5.jpg" alt=""></li> <li><img x-src="img/1.jpg" alt=""></li> <li><img x-src="img/2.jpg" alt=""></li> <li><img x-src="img/3.jpg" alt=""></li> <li><img x-src="img/4.jpg" alt=""></li> <li><img x-src="img/5.jpg" alt=""></li> <li><img x-src="img/1.jpg" alt=""></li> <li><img x-src="img/2.jpg" alt=""></li> <li><img x-src="img/3.jpg" alt=""></li> <li><img x-src="img/4.jpg" alt=""></li> <li><img x-src="img/5.jpg" alt=""></li> </ul></div><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript"> $(function(){ function showImg(){ $(‘img‘).each(function(index,ele){ if($(this).offset().top<$(window).height()+$(window).scrollTop()){ var oSrc = $(this).attr(‘x-src‘); $(this).attr(‘src‘,oSrc); } }) } showImg(); $(window).scroll(function(){ showImg(); }); });</script></body></html>
延时加载图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。