This repository was archived by the owner on Feb 6, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
webcomponents/lazy-img/src Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,18 @@ export namespace Components {
1414
1515 interface DeckgoLazyImg {
1616 'imgAlt' : string ;
17+ 'imgSizes' : string ;
1718 'imgSrc' : string ;
19+ 'imgSrcSet' : string ;
1820 'lazyLoad' : ( ) => Promise < void > ;
1921 'observerRootMargin' : string ;
2022 'observerThreshold' : number | number [ ] ;
2123 }
2224 interface DeckgoLazyImgAttributes extends StencilHTMLAttributes {
2325 'imgAlt' ?: string ;
26+ 'imgSizes' ?: string ;
2427 'imgSrc' ?: string ;
28+ 'imgSrcSet' ?: string ;
2529 'observerRootMargin' ?: string ;
2630 'observerThreshold' ?: number | number [ ] ;
2731 'onLazyImgDidLoad' ?: ( event : CustomEvent ) => void ;
Original file line number Diff line number Diff line change @@ -14,9 +14,15 @@ export class DeckdeckgoLazyImg {
1414 @Prop ( { reflectToAttr : true } )
1515 imgSrc : string ;
1616
17+ @Prop ( { reflectToAttr : true } )
18+ imgSrcSet : string ;
19+
1720 @Prop ( { reflectToAttr : true } )
1821 imgAlt : string ;
1922
23+ @Prop ( { reflectToAttr : true } )
24+ imgSizes : string ;
25+
2026 @Prop ( )
2127 observerRootMargin : string = '100px 0px' ;
2228
@@ -80,11 +86,17 @@ export class DeckdeckgoLazyImg {
8086 img . removeAttribute ( 'data-src' ) ;
8187 }
8288
89+ if ( img && img . hasAttribute ( 'data-srcset' ) ) {
90+ img . setAttribute ( 'srcset' , img . getAttribute ( 'data-srcset' ) ) ;
91+ img . removeAttribute ( 'data-srcset' ) ;
92+ }
93+
8394 resolve ( ) ;
8495 } ) ;
8596 }
8697
8798 render ( ) {
88- return < img data-src = { this . imgSrc } alt = { this . imgAlt ? this . imgAlt : this . imgSrc } /> ;
99+ return < img data-src = { this . imgSrc } alt = { this . imgAlt ? this . imgAlt : this . imgSrc }
100+ data-srcset = { this . imgSrcSet ? this . imgSrcSet : undefined } sizes = { this . imgSizes ? this . imgSizes : undefined } /> ;
89101 }
90102}
Original file line number Diff line number Diff line change 4242 < deckgo-lazy-img img-src ="https://deckdeckgo.com/assets/img/deckdeckgo.png "> </ deckgo-lazy-img >
4343 < deckgo-lazy-img img-src ="https://deckdeckgo.com/assets/img/deckdeckgo.png "> </ deckgo-lazy-img >
4444
45+ < deckgo-lazy-img style ="background: red; "
46+ img-sizes ="(min-width: 40em) 80vw, 100vw "
47+ img-src-set ="https://deckdeckgo.com/assets/img/deckdeckgo.png 1x, https://deckdeckgo.com/assets/img/deckdeckgo.svg 2x "> </ deckgo-lazy-img >
48+
4549</ body >
4650</ html >
You can’t perform that action at this time.
0 commit comments