jQuery Picture
jQuery picture is a neat little tool that allows you to serve responsive images depending on the width of the users viewport. While it provides a solution for responsive image files sizes it still sets the largest version as the standard src
value and requires the web editor to enter additional data attributes to the <figure>
element of the image.
If you’re looking for a server side solution then something like Adaptive Images may suite your needs a little better.
You have a choice of two ways to use the plugin, with <figure>
tags or with the newly proposed <picture>
and <source>
tags. Bear in mind that the picture and source tags have only recently been proposed and are not yet valid HTML code (also note that WebKit have just launched srcset support for webkit nightly).
Initialise the plugin
To initialise it you just add .picture()
to the element you want to apply it to. It only works on figure and picture tags for now:
$(function(){ $('figure.responsive').picture(); });
See the Pen jQuery Picture by Justin Avery (@justincavery) on CodePen