Skip to content

Commit 170266f

Browse files
committed
Merge branch 'release/1.0.0-alpha.8' into master
2 parents 0213630 + e24bcd8 commit 170266f

File tree

16 files changed

+273
-75
lines changed

16 files changed

+273
-75
lines changed

demo/src/css/styles.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ main {
2020
display: none;
2121
}
2222

23-
.lazyload {
24-
opacity: 0;
25-
}
26-
27-
.lazyloaded {
28-
// opacity: 1;s
29-
}
30-
3123
[data-breakpoint]::after,
3224
[data-breakpoint]::before {
3325
z-index: -999;

demo/src/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
</button>
154154
<div data-ref="container" class="relative overflow-hidden" aria-hidden="true">
155155
<div data-ref="content" class="w-full p-4 pt-0">
156-
<img src="https://placekitten.com/200/100" width="200" height="100" alt="" />
156+
<img data-options='{ "log": true }' data-src="https://placekitten.com/200/100" width="200" height="100" alt="" />
157157
</div>
158158
</div>
159159
</div>
@@ -168,7 +168,7 @@
168168
</button>
169169
<div data-ref="container" class="relative overflow-hidden" aria-hidden="true">
170170
<div data-ref="content" class="w-full p-4 pt-0">
171-
<img src="https://placekitten.com/200/120" width="200" height="120" alt="" />
171+
<img data-src="https://placekitten.com/200/120" width="200" height="120" alt="" />
172172
</div>
173173
</div>
174174
</div>
@@ -183,7 +183,7 @@
183183
</button>
184184
<div data-ref="container" class="relative overflow-hidden" aria-hidden="true">
185185
<div data-ref="content" class="w-full p-4 pt-0">
186-
<img src="https://placekitten.com/200/80" width="200" height="80" alt="" />
186+
<img data-src="https://placekitten.com/200/80" width="200" height="80" alt="" />
187187
</div>
188188
</div>
189189
</div>
@@ -217,10 +217,10 @@ <h2 id="components-tabs" class="text-lg mb-4">Tabs</h2>
217217
ac aliquam purus finibus. Pellentesque aliquet augue non sollicitudin semper. Vivamus
218218
est odio, efficitur vitae lacus id, eleifend maximus felis.
219219
</div>
220-
<div data-ref="content" aria-hidden="true">
220+
<div data-ref="content" aria-hidden="true" style="display: none;">
221221
<img
222-
data-src="https://placekitten.com/300/300"
223-
class="lazyload"
222+
data-src="https://placekitten.com/299/299"
223+
data-options='{ "log": true }'
224224
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
225225
width="300"
226226
height="300"

demo/src/js/app.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { Base, Modal, MediaQuery, Tabs, Accordion } from '../../../src';
33
class App extends Base {
44
get config() {
55
return {
6-
log: true,
76
name: 'App',
87
components: {
98
Accordion,
109
Cursor: () => import('./components/Cursor'),
1110
Skew: () => import('./components/Skew'),
11+
'[data-src]': () => import('./components/Lazyload'),
1212
Modal,
1313
MediaQuery,
1414
Tabs,
@@ -21,8 +21,6 @@ class App extends Base {
2121
}
2222

2323
loaded() {
24-
// eslint-disable-next-line
25-
// import('lazysizes');
2624
this.$log('Loaded');
2725
}
2826

demo/src/js/components/Lazyload.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Base } from '../../../../src';
2+
import transition, { setClassesOrStyles } from '../../../../src/utils/css/transition';
3+
4+
export default class Lazyload extends Base {
5+
get config() {
6+
return {
7+
name: 'Lazyload',
8+
styles: {
9+
unloaded: { opacity: 0 },
10+
active: { transition: 'opacity 0.5s' },
11+
loaded: '',
12+
},
13+
};
14+
}
15+
16+
mounted() {
17+
setClassesOrStyles(this.$el, this.$options.styles.unloaded);
18+
19+
this.observer = new IntersectionObserver(
20+
([entry]) => {
21+
if (entry.isIntersecting) {
22+
window.requestIdleCallback(this.load);
23+
}
24+
},
25+
{
26+
threshold: 1.0,
27+
}
28+
);
29+
}
30+
31+
loaded() {
32+
this.observer.observe(this.$el);
33+
}
34+
35+
destroyed() {
36+
this.observer.disconnect();
37+
}
38+
39+
load() {
40+
const { unloaded, active, loaded } = this.$options.styles;
41+
const src = this.$el.getAttribute('data-src');
42+
const img = new Image();
43+
img.onload = () => {
44+
this.$el.setAttribute('src', src);
45+
this.$el.removeAttribute('data-src');
46+
transition(this.$el, {
47+
from: unloaded,
48+
active,
49+
to: loaded,
50+
});
51+
setClassesOrStyles(this.$el, loaded);
52+
this.$destroy();
53+
};
54+
img.src = src;
55+
}
56+
}

dist/abstracts/Base.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/abstracts/Base.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/components/Accordion/AccordionItem.js

Lines changed: 121 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)