<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>图片懒加载 on 我的博客</title><link>https://blog.suoyiran.tech/tags/%E5%9B%BE%E7%89%87%E6%87%92%E5%8A%A0%E8%BD%BD/</link><description>Recent content from 我的博客</description><generator>Hugo</generator><language>zh-CN</language><copyright>本博客所有文章除特别声明外，均采用 BY-NC-SA 许可协议。转载请注明出处！</copyright><lastBuildDate>Sun, 10 Mar 2019 10:41:00 +0800</lastBuildDate><atom:link href="https://blog.suoyiran.tech/tags/%E5%9B%BE%E7%89%87%E6%87%92%E5%8A%A0%E8%BD%BD/index.xml" rel="self" type="application/rss+xml"/><item><title>图片懒加载组件</title><link>https://blog.suoyiran.tech/post/%E5%9B%BE%E7%89%87%E6%87%92%E5%8A%A0%E8%BD%BD%E7%BB%84%E4%BB%B6/</link><pubDate>Sun, 10 Mar 2019 10:41:00 +0800</pubDate><guid>https://blog.suoyiran.tech/post/%E5%9B%BE%E7%89%87%E6%87%92%E5%8A%A0%E8%BD%BD%E7%BB%84%E4%BB%B6/</guid><description>
<![CDATA[<h1>图片懒加载组件</h1><p>作者：前端老李（<no value>）</p>
        
          <h2 id="代码片段地址">
<a class="header-anchor" href="#%e4%bb%a3%e7%a0%81%e7%89%87%e6%ae%b5%e5%9c%b0%e5%9d%80"></a>
代码片段地址
</h2><p>可直接点击链接在微信开发者工具上查看 <a href="https://developers.weixin.qq.com/s/JwRyKEmp7i5U">https://developers.weixin.qq.com/s/JwRyKEmp7i5U</a></p>
<h2 id="效果预览图">
<a class="header-anchor" href="#%e6%95%88%e6%9e%9c%e9%a2%84%e8%a7%88%e5%9b%be"></a>
效果预览图
</h2><p><img src="/post/%E5%9B%BE%E7%89%87%E6%87%92%E5%8A%A0%E8%BD%BD%E7%BB%84%E4%BB%B6/gitpic/preview.gif" alt=""></p>
<p>建议使用微信开发者工具直接打开上面的代码片段查看效果</p>
<h2 id="起步">
<a class="header-anchor" href="#%e8%b5%b7%e6%ad%a5"></a>
起步
</h2><p>小程序图片的懒加载只能在page或scrollView中使用，通过阅读小程序api，发现一个<code>createIntersectionObserver</code>接口<a href="https://developers.weixin.qq.com/miniprogram/dev/api/wx.createIntersectionObserver.html">此处是介绍文档</a>，他可以监听某个页面元素在视口的位置，这样我们就可以监听图片组件是否进入了用户视线中，进入之后再去加载网络图片，实现懒加载的功能。</p>
        
        <hr><p>本文2019-03-10首发于<a href='https://blog.suoyiran.tech/'>我的博客</a>，最后修改于2019-03-10</p>]]></description><category>微信小程序</category></item></channel></rss>