Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

add new API fxSrc for responsive features Image element #81

Closed
ThomasBurleson opened this issue Jan 4, 2017 · 7 comments · Fixed by #384 or #382
Closed

add new API fxSrc for responsive features Image element #81

ThomasBurleson opened this issue Jan 4, 2017 · 7 comments · Fixed by #384 or #382
Labels
feature has pr A PR has been created to address this issue
Milestone

Comments

@ThomasBurleson
Copy link
Contributor

ThomasBurleson commented Jan 4, 2017

Similar to responsive features in the picture element

<picture>
  <source  media="(min-width: 650px)"    srcset="images/kitten-stretching.png">
  <source  media="(min-width: 465px)"    srcset="images/kitten-sitting.png">
  <img  src="images/kitten-curled.png"  alt="a cute kitten">
</picture>

or 

<picture>
  <source media="(min-width: 800px)"
          sizes="80vw"
          srcset="lighthouse-landscape-640.jpg 640w,
                  lighthouse-landscape-1280.jpg 1280w,
                  lighthouse-landscape-2560.jpg 2560w">
  <img src="lighthouse-160.jpg" alt="lighthouse"
       sizes="80vw"
       srcset="lighthouse-160.jpg 160w,
               lighthouse-320.jpg 320w,
               lighthouse-640.jpg 640w,
               lighthouse-1280.jpg 1280w">
</picture>

``

Enable adaptive layouts with:

```html
<img 
     fxSrc="images/kitten-curled.png" 
     fxSrc.xs="images/kitten-sitting.png"
     fxSrc.sm="images/kitten-stretching.png"
/>

<!-- Or use SrcSet to wrap image in `<picture>` with `<source>` entries -->
<img 
     [fxSrcSet]="srcSet1" 
     [fxSrcSet.gt-sm]="srcSet2"
/>

see https://www.html5rocks.com/en/tutorials/responsive/picture-element/

@ThomasBurleson ThomasBurleson changed the title add responsive features Image element with the *fxSrc* directive add new API fxSrc for responsive features Image element Jan 4, 2017
@ThomasBurleson ThomasBurleson added the P5 Low-priority issue that needs consideration label Jun 22, 2017
@benbraou
Copy link

I had a similar need in a personal project using @angular/flex-layout.
So, I created a library angular-flex-picture (https://github.com/benbraou/angular-flex-picture)

<picture>
  <source [flexMedia]="'xs'" srcset="https://dummyimage.com/300x200/d607d6/fff.png&text=xs">
  <source [flexMedia]="'md'" srcset="https://dummyimage.com/500x300/0820d4/fff.png&text=md">
  <img src="https://dummyimage.com/600x400/ffffff/000000.png&text=default" style="width:auto;">
</picture>

But, I just found out about this issue.
@ThomasBurleson : are you open to a PR that implements the specifications you mentioned above ? I should have time in the next month during my weekends.

Thanks

@ThomasBurleson
Copy link
Contributor Author

ThomasBurleson commented Jul 20, 2017

@benbraou - YES! plz submit a PR and let's get this feature into the core of @angular/flex-layout.

Instead of using flexMedia, I suggest a better approach would be the following directive:

<picture>
  <img  style="width:auto;"
        src="https://dummyimage.com/600x400/ffffff/000000.png" 
        srcset.xs="https://dummyimage.com/300x200/d607d6/fff.png"
        srcset.md="https://dummyimage.com/500x300/0820d4/fff.png" >
</picture>

Where srcset.xs is a flex-layout directive that injects <source> element:

<source media="(min-width: 600px)"
              srcset="https://dummyimage.com/300x200/d607d6/fff.png" >

@ThomasBurleson ThomasBurleson added this to the v2.0.0-beta.10 milestone Jul 20, 2017
@benbraou
Copy link

Thanks for the quick reply!
Indeed, I agree with your approach.
I'll take this issue then ^^

@benbraou
Copy link

benbraou commented Aug 5, 2017

I am working on this issue this weekend.

@mackelito
Copy link

I'm so looking forward to seeing this. 😁

benbraou added a commit to benbraou/flex-layout that referenced this issue Aug 6, 2017
…port responsive images

Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> element.

Closes angular#81.
benbraou added a commit to benbraou/flex-layout that referenced this issue Aug 8, 2017
…port responsive images

Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> element.

Closes angular#81.
benbraou added a commit to benbraou/flex-layout that referenced this issue Aug 8, 2017
…port responsive images

Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> element.

Closes angular#81.
benbraou added a commit to benbraou/flex-layout that referenced this issue Aug 9, 2017
…port responsive images

Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> element.

Closes angular#81.
benbraou added a commit to benbraou/flex-layout that referenced this issue Aug 10, 2017
…port responsive images

Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> element.

Closes angular#81.
@ThomasBurleson ThomasBurleson added has pr A PR has been created to address this issue and removed P5 Low-priority issue that needs consideration labels Aug 10, 2017
@ThomasBurleson ThomasBurleson modified the milestones: v2.0.0-beta.9, v2.0.0-beta.10 Aug 10, 2017
benbraou added a commit to benbraou/flex-layout that referenced this issue Aug 15, 2017
…port responsive images

Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> element.

Closes angular#81.
ThomasBurleson pushed a commit that referenced this issue Aug 15, 2017
…port responsive images

Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> element.

Closes #81.
ThomasBurleson added a commit that referenced this issue Aug 17, 2017
* add responsive API to img.src:  src.md, src.lt-lg, src.gt-xs, etc.
* repackage API classes to easily distinguish flexbox APIs and  extended responsive APIs
* fix ImgSrcsetDirective to support usages without `<picture>` parents

Closes #366, Fixes #81, Fixes #376.
ThomasBurleson pushed a commit that referenced this issue Aug 17, 2017
Inject a <source> element for every `srcset.<breakpoint alias>` in the HTML markup of an <img> element contained in a <picture> element.

Closes #81.
ThomasBurleson added a commit that referenced this issue Aug 17, 2017
…ements

* add responsive API to img.src:  src.md, src.lt-lg, src.gt-xs, etc.
* repackage API classes to easily distinguish flexbox APIs and  extended responsive APIs
* fix ImgSrcsetDirective to support usages without `<picture>` parents

Closes #366, Fixes #81, Fixes #376.
ThomasBurleson added a commit that referenced this issue Aug 18, 2017
Support responsive image by introducing srcset.<breakpoint alias> directive. When used as <img> attributes where

*  where the <img> is a child of a <picture> container, this directive will injects a <source> element for every srcset.<breakpoint alias>.
*  where the <img> is NOT nested in a <picture> element, then the `img.src` property will be responsively updated.

> Thanks to @benbraou for his initial PR submission (@see #366)

Closes #81.
ThomasBurleson added a commit that referenced this issue Aug 24, 2017
* add ImgSrcsetDirective
  *  to inject <source> elements to support responsive images
  *  Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> elemen
  *  support usages without `<picture>` parents
* add responsive API to img.src:  src.md, src.lt-lg, src.gt-xs, etc.
* repackage API classes to easily distinguish flexbox APIs and  extended responsive APIs

Closes #366, Fixes #81, Fixes #376.
ThomasBurleson added a commit that referenced this issue Aug 24, 2017
* add ImgSrcsetDirective
  *  to inject <source> elements to support responsive images
  *  Inject a <source> element for every srcset.<breakpoint alias> in the HTML markup of an <img> element contained in a <picture> elemen
  *  support usages without `<picture>` parents
* add responsive API to img.src:  src.md, src.lt-lg, src.gt-xs, etc.
* skip actions if responsive keys are not defined
  *  without responsive keys (`src.<alias>`) defined, the ImgSrcDirective should
*fall-through* and not change any attributes or properties on the `img` DOM element. The `img.src` attribute is dynamically set only when responsive keys are defined.
    * defaults to `src=""` if not explicitly assigned
    * responsive key activation will then assign the activated value to `img.src` attribute.

Closes #366, Fixes #81, Fixes #376.
ThomasBurleson added a commit that referenced this issue Aug 31, 2017
* add responsive API to img[src.md], img[src.lt-lg], img[src.gt-xs], etc.
* skip actions if responsive keys are not defined
  *  without responsive keys (`src.<alias>`) defined, the ImgSrcDirective should **fall-through** and not change any attributes or properties on the `img` DOM element. The `img.src` attribute is dynamically set only when responsive keys are defined.
    * defaults to `src=""` if not explicitly assigned
    * responsive key activation will then assign the activated value to `img.src` attribute.

Closes #366, Fixes #81, Fixes #376.
tinayuangao pushed a commit that referenced this issue Sep 7, 2017
* add responsive API to img[src.md], img[src.lt-lg], img[src.gt-xs], etc.
* skip actions if responsive keys are not defined
  *  without responsive keys (`src.<alias>`) defined, the ImgSrcDirective should **fall-through** and not change any attributes or properties on the `img` DOM element. The `img.src` attribute is dynamically set only when responsive keys are defined.
    * defaults to `src=""` if not explicitly assigned
    * responsive key activation will then assign the activated value to `img.src` attribute.

Closes #366, Fixes #81, Fixes #376.
@mackelito
Copy link

mackelito commented Oct 9, 2017

@ThomasBurleson
Btw.. will this have x2/X3... support?
for use like:
<img src='illustration-small.png' srcset='images/illustration-small.png 1x, images/illustration-big.png 2x' style='max-width: 500px'/>

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.