File tree Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -26,12 +26,18 @@ class="{{ $class }}"
26
26
<img
27
27
{!! $attributes ?? ' ' ! !}
28
28
class =" {{ $class } }"
29
+ @if ($presets [' placeholder' ] ?? false )
30
+ style =" background-image : url (' {{ $presets[' placeholder ' ] }}' ); background-size : contain ; background-position : center ; background-repeat : no-repeat ;"
31
+ @endif
29
32
src =" {{ $presets [' placeholder' ] ?? $image -> url () } }"
30
33
alt =" {{ $alt ?? $image -> alt () } }"
31
34
width =" {{ $width } }"
32
35
height =" {{ $height } }"
33
36
onload ="
34
- this.onload=null;
37
+ this.onload=()=>{
38
+ this.style.backgroundImage = null;
39
+ this.onload=null
40
+ };
35
41
window.responsiveResizeObserver.observe(this);
36
42
"
37
43
>
Original file line number Diff line number Diff line change 1
1
<script >
2
- window .responsiveResizeObserver = new ResizeObserver ((entries ) => {
3
- entries .forEach (entry => {
4
- const bounds = entry .target .getBoundingClientRect ();
5
- const imgWidth = bounds .width ;
6
- const imgHeight = bounds .height ;
7
- const pixelRatio = window .devicePixelRatio * imgWidth;
8
-
9
- requestAnimationFrame (() => entry .target .parentNode .querySelectorAll (' source' ).forEach ((source ) => {
10
- source .sizes = pixelRatio + ' px' ;
11
- }));
2
+ window .responsiveResizeObserver = new ResizeObserver (async (entries ) => {
3
+ entries .forEach (entry => {
4
+ let imgWidth = entry .devicePixelContentBoxSize [0 ].inlineSize ;
5
+
6
+ if (imgWidth === 0 ) {
7
+ return ;
8
+ }
9
+
10
+ requestAnimationFrame (() => {
11
+ entry .target .loading = ' lazy' ;
12
+ entry .target .parentNode .querySelectorAll (' source' ).forEach ((source ) => {
13
+ source .sizes = imgWidth + ' px'
14
+ })
12
15
});
13
- });
16
+ })
17
+ });
14
18
</script >
You can’t perform that action at this time.
0 commit comments