chore(deps): use lazysizes
to load images
This commit is contained in:
parent
7651d2851b
commit
ca41c7ebff
10 changed files with 26 additions and 32 deletions
|
@ -49,8 +49,8 @@ magnific-popup:
|
||||||
css: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/magnific-popup.min.css
|
css: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/magnific-popup.min.css
|
||||||
js: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/jquery.magnific-popup.min.js
|
js: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/jquery.magnific-popup.min.js
|
||||||
|
|
||||||
lozad:
|
lazysizes:
|
||||||
js: https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js
|
js: https://cdn.jsdelivr.net/npm/lazysizes@5.3.2/lazysizes.min.js
|
||||||
|
|
||||||
clipboard:
|
clipboard:
|
||||||
js: https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js
|
js: https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js
|
||||||
|
|
|
@ -38,8 +38,8 @@ magnific-popup:
|
||||||
css: /assets/lib/magnific-popup-1.1.0/magnific-popup.css
|
css: /assets/lib/magnific-popup-1.1.0/magnific-popup.css
|
||||||
js: /assets/lib/magnific-popup-1.1.0/jquery.magnific-popup.min.js
|
js: /assets/lib/magnific-popup-1.1.0/jquery.magnific-popup.min.js
|
||||||
|
|
||||||
lozad:
|
lazysizes:
|
||||||
js: /assets/lib/lozad-1.16.0/lozad.min.js
|
js: /assets/lib/lazysizes-5.3.2/lazysizes.min.js
|
||||||
|
|
||||||
clipboard:
|
clipboard:
|
||||||
js: /assets/lib/clipboard-2.0.9/clipboard.min.js
|
js: /assets/lib/clipboard-2.0.9/clipboard.min.js
|
||||||
|
|
|
@ -15,12 +15,11 @@
|
||||||
{% if page.layout == 'post' or page.layout == 'page' %}
|
{% if page.layout == 'post' or page.layout == 'page' %}
|
||||||
<!-- image lazy-loading & popup & clipboard -->
|
<!-- image lazy-loading & popup & clipboard -->
|
||||||
{% assign _urls = site.data.assets[origin].magnific-popup.js
|
{% assign _urls = site.data.assets[origin].magnific-popup.js
|
||||||
| append: ',' | append: site.data.assets[origin].lozad.js
|
| append: ',' | append: site.data.assets[origin].lazysizes.js
|
||||||
| append: ',' | append: site.data.assets[origin].clipboard.js
|
| append: ',' | append: site.data.assets[origin].clipboard.js
|
||||||
%}
|
%}
|
||||||
|
|
||||||
{% include jsdelivr-combine.html urls=_urls %}
|
{% include jsdelivr-combine.html urls=_urls %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page.layout == 'home'
|
{% if page.layout == 'home'
|
||||||
|
|
|
@ -115,7 +115,14 @@
|
||||||
|
|
||||||
{% endunless %}
|
{% endunless %}
|
||||||
|
|
||||||
<!-- lazy-load images <https://github.com/ApoorvSaxena/lozad.js#usage> -->
|
<!-- lazy-load images <https://github.com/aFarkas/lazysizes#readme> -->
|
||||||
|
|
||||||
|
{% if _left contains 'class=' %}
|
||||||
|
{% assign _left = _left | replace: 'class="', 'class="lazyload ' %}
|
||||||
|
{% else %}
|
||||||
|
{% assign _left = _left | replace: 'src=', 'class="lazyload" src=' %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% assign _left = _left | replace: 'src=', 'data-src=' %}
|
{% assign _left = _left | replace: 'src=', 'data-src=' %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/**
|
/**
|
||||||
Lazy load images (https://github.com/ApoorvSaxena/lozad.js)
|
Set up image popup stuff (https://github.com/dimsemenov/Magnific-Popup)
|
||||||
and popup when clicked (https://github.com/dimsemenov/Magnific-Popup)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
@ -10,12 +9,6 @@ $(function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lazy loading */
|
|
||||||
|
|
||||||
const imgList = document.querySelectorAll(`${IMG_SCOPE} img[data-src]`);
|
|
||||||
const observer = lozad(imgList);
|
|
||||||
observer.observe();
|
|
||||||
|
|
||||||
/* popup */
|
/* popup */
|
||||||
|
|
||||||
$(`${IMG_SCOPE} p > img[data-src], ${IMG_SCOPE} img[data-src].preview-img`).each(
|
$(`${IMG_SCOPE} p > img[data-src], ${IMG_SCOPE} img[data-src].preview-img`).each(
|
||||||
|
|
|
@ -183,22 +183,17 @@ i { /* fontawesome icons */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@-webkit-keyframes fade-in {
|
|
||||||
from { opacity: 0; }
|
|
||||||
to { opacity: 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes fade-in {
|
|
||||||
from { opacity: 0; }
|
|
||||||
to { opacity: 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
img[data-src] {
|
img[data-src] {
|
||||||
margin: 0.5rem 0;
|
margin: 0.5rem 0;
|
||||||
|
|
||||||
&[data-loaded="true"] {
|
&.lazyload,
|
||||||
-webkit-animation: fade-in linear 0.5s;
|
&.lazyloading {
|
||||||
animation: fade-in linear 0.5s;
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.lazyloaded {
|
||||||
|
opacity: 1;
|
||||||
|
transition: opacity 0.5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.left {
|
&.left {
|
||||||
|
|
|
@ -30,7 +30,7 @@ img.preview-img {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
|
||||||
&.bg[data-loaded="true"] {
|
&.bg {
|
||||||
background: var(--preview-img-bg);
|
background: var(--preview-img-bg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
assets/js/dist/page.min.js
vendored
2
assets/js/dist/page.min.js
vendored
File diff suppressed because one or more lines are too long
2
assets/js/dist/post.min.js
vendored
2
assets/js/dist/post.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
Subproject commit 5d177b3cbbea89e3392eb48c0ee580c6a0ce41d1
|
Subproject commit e372141074f370c6f03b68b5264e7663f2b7477c
|
Loading…
Reference in a new issue