USING RESPONSIVE IMAGES (NOW) By ChenHuiJing / @hj_chen SO YOU - - PowerPoint PPT Presentation

using responsive images now
SMART_READER_LITE
LIVE PREVIEW

USING RESPONSIVE IMAGES (NOW) By ChenHuiJing / @hj_chen SO YOU - - PowerPoint PPT Presentation

USING RESPONSIVE IMAGES (NOW) By ChenHuiJing / @hj_chen SO YOU WANT TO BUILD A RESPONSIVE WEBSITE? THE OBESITY PROBLEM Source: httparchive >60%fromimages LOSE-LOSE SITUATION BlurryimageonHD5K 5mbpixel-denseimageon


slide-1
SLIDE 1

USING RESPONSIVE IMAGES (NOW)

By / Chen Hui Jing @hj_chen

slide-2
SLIDE 2

SO YOU WANT TO BUILD A RESPONSIVE WEBSITE?

slide-3
SLIDE 3

Source:

>60% from images

THE OBESITY PROBLEM

http archive

slide-4
SLIDE 4

Blurry image on HD 5K display? 5mb pixel-dense image on 3.8inch Nokia phone?

LOSE-LOSE SITUATION

slide-5
SLIDE 5

POTENTIAL SOLUTIONS

Requires additional development effort for it to place nice in your project Server-side solution; Dependent on PHP; May need to mess around with server configuration Mostly experimental; Not advisable for production sites Not scalable for image heavy sites; Fails validation; Not semantic WURFL.js Adaptive image Using cookies Hack <img>

slide-6
SLIDE 6

<SRCSET> AND <PICTURE>

Responsive image solution native to the browser.

Refer to for all the details. latest specification

slide-7
SLIDE 7
slide-8
SLIDE 8

THE <SRCSET> ATTRIBUTE

Declare comma-separated list of image sources, which browsers will serve according to certain conditions we specify using descriptors.

slide-9
SLIDE 9

DESCRIPTORS

x descriptors indicate the pixel-density of an image w descriptors indicate the width of an image

slide-10
SLIDE 10

THE <SIZES> ATTRIBUTE

Specify the intended display size of the image Must be present if w descriptors are used Syntax: <media-condition> <CSS length>

You can't use percentages for the second condition. The only relative CSS lengths you can use are viewport units.

sizes="(max-width: 400px) 100vw, (max-width: 960px) 75vw, 640px"

slide-11
SLIDE 11

FIXED WIDTH IMAGES

<img srcset="crest-383.jpg 1.5x, crest-510.jpg 2x" src="crest-255.jpg" alt="USWNT crest" />

slide-12
SLIDE 12

FLUID WIDTH IMAGES

<img srcset="uswnt-480.jpg 480w, uswnt-640.jpg 640w, uswnt-960.jpg 960w, uswnt-1280.jpg 1280w" sizes="(max-width: 400px) 100vw, (max-width: 960px) 75vw, 640px" src="uswnt-640.jpg" alt="USWNT World Cup victory">

slide-13
SLIDE 13

THE <PICTURE> ELEMENT

A wrapper for the image and its sources. Will not work without an <img> element.

<picture> <source media="(min-width: 40rem)" srcset="full-large.jpg 1024w, full-medium.jpg 640w, full-small.jpg 320w" sizes="33.3vw" /> <source srcset="cropped-large.jpg 2x, cropped-small.jpg 1x" /> <img src="full-small.jpg" alt="An awesome image" /> </picture>

slide-14
SLIDE 14

THE <SOURCE> ELEMENT

Allows us to declare multiple sets of image sources. Syntax: <media attribute>|<type attribute> <srcset attribute>

<source media="(min-width: 1280px)" srcset="wide-large.jpg 1280w, wide-medium.jpg 960w, wide-small.jpg 640w" <source media="(min-width: 960px)" srcset="cropped-large.jpg 960w, cropped-medium.jpg 720w, cropped-small.jpg 480w" <source srcset="narrow-large.jpg 2x, narrow-small.jpg 1x">

slide-15
SLIDE 15

ART DIRECTION USE-CASE

<picture> <source media="(min-width: 960px)" srcset="ticker-tape-large.jpg"> <source media="(min-width: 575px)" srcset="ticker-tape-medium.jpg"> <img src="ticker-tape-small.jpg" alt="USWNT ticker-tape parade"> </picture>

slide-16
SLIDE 16

IMAGE FORMAT USE-CASE

Order of source matters. Falls back to original <img> element.

<picture> <source type="image/vnd.ms-photo" src="wwc2015.jxr"> <source type="image/jp2" src="wwc2015.jp2"> <source type="image/webp" src="wwc2015.webp"> <img src="wwc2015.png" alt="WWC 2015"> </picture>

slide-17
SLIDE 17

CAN I USE...SRCSET?

slide-18
SLIDE 18

CAN I USE...PICTURE?

slide-19
SLIDE 19

POLYFILL

The go-to polyfill for responsive images is by . Picturefill Scott Jehl

slide-20
SLIDE 20

TO FIND OUT MORE...

by with by by by Native Responsive Images Yoav Weiss Responsive images get real Mat Marquis The anatomy of responsive images Jake Archibald Srcset and sizes Eric Portis Responsive Images 101 Jason Grigsby

slide-21
SLIDE 21

FOR LATEST UPDATES...

Join the . Sign up for their . Follow the RICG on . Responsive Images Community Group newsletter Twitter

slide-22
SLIDE 22

THE END

http://www.chenhuijing.com @hj_chen @hj_chen @huijing