srcset-polyfill
srcset-polyfill copied to clipboard
Export main() and Granular control of which image is used
I'll maybe try to fork the library and upload my version, but I haven't gotten to that point yet. In the mean time, please just look my implementation over: http://blog.hilmor.com/wp-content/themes/retool/_inc/srcset.js
The biggest needs I had for the library were:
- being able to re-call the script when the window size changed or onorientationchange. So I exported main() to the window.
- not adding the src="" value into the list of srcset="" values. It produced behavior that wasn't easily controlled.
- not assuming that a bigger screen meant needing a bigger image. In my layouts, there were three targets: smartphone had the small image, tablet had the large image and desktop had the medium image.
- when I resize down to smartphone, the smaller image was needed again, not the large one. This may have been poor design on my part as I wasn't using squishy images. Had I been, once the larger image was loaded, it could have squished down to the smaller size without issue.
- I kept getting a bunch of errors in older IEs, thus the pedantic validation. Probably wasn't the best approach
Please merge in the functionality you deem appropriate. If you don't I may fork one eventually, but don't hold your breath.
Scott, can you elaborate on what unexpected behavior having both @src and @srcset resulted in?
Regarding resizing, see the discussion here: https://github.com/borismus/srcset-polyfill/pull/17
I don't care about older IEs, but if you have a fix, please submit a PR.