Fixed image lazy loading.
This commit is contained in:
parent
171faafc67
commit
cfb67a1cb9
3 changed files with 13 additions and 6 deletions
|
@ -1,7 +1,8 @@
|
||||||
<!-- image lazy load: https://github.com/ApoorvSaxena/lozad.js -->
|
<!-- image lazy load: https://github.com/ApoorvSaxena/lozad.js -->
|
||||||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js"></script>
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const el = document.querySelectorAll('#post-wrapper img');
|
const imgs = document.querySelectorAll('#post-wrapper img');
|
||||||
const observer = lozad(el);
|
const observer = lozad(imgs);
|
||||||
observer.observe();
|
observer.observe();
|
||||||
</script>
|
</script>
|
|
@ -64,13 +64,19 @@ layout: default
|
||||||
</div> <!-- .post-meta -->
|
</div> <!-- .post-meta -->
|
||||||
|
|
||||||
<div class="post-content">
|
<div class="post-content">
|
||||||
|
|
||||||
{% if page.image %}
|
{% if page.image %}
|
||||||
<img src="{{ page.image }}">
|
<img src="{{ page.image }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<!-- Add lozad class into image tags. see: <https://github.com/ApoorvSaxena/lozad.js#usage> -->
|
||||||
{{ content }}
|
{% if content contains '<img src=' %}
|
||||||
|
{% capture loading %}
|
||||||
|
{{ "/assets/img/commons/loading.png" | relative_url }}
|
||||||
|
{% endcapture %}
|
||||||
|
{% assign replacement = '<img src=' | append: loading | append: ' data-src=' %}
|
||||||
|
{{ content | replace: '<img src=', replacement }}
|
||||||
|
{% else %}
|
||||||
|
{{ content }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="post-tail-wrapper text-muted">
|
<div class="post-tail-wrapper text-muted">
|
||||||
|
|
BIN
assets/img/commons/loading.png
Normal file
BIN
assets/img/commons/loading.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 99 B |
Loading…
Reference in a new issue