Skip to content

Export main() and Granular control of which image is used #13

@scottconnerly

Description

@scottconnerly

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions