html简单图片懒加载js代码
当网页图片太多时,网页加载就会变慢,这时候如果有延迟加载图片就可以提升网页加载速度。。
我们只需要在img图片代码部分修改成如下所示:
src="https://ws3.sinaimg.cn/large/005BYqpgly1fycavmvp0yg301o01owea.jpg" data-echo="你的图片地址"" width="100%" height="auto" alt=""接着在网页底部footer里面加入一下js即可。。
<script src="https://www.oxx0.com/js/echo.js"></script> <script> echo.init({ offset: 100, throttle: 250, unload: false, callback: function (element, op) { console.log(element, 'has been', op + 'ed') } });// ***图片懒加载***// </script>