Slide 1

Slide 1 text

Scalable Vector Graphics. Next Level Ilya Pukhalski, April 2014

Slide 2

Slide 2 text

@pukhalski ! Solution Architect, EPAM Systems Lecturer, British Higher School of Art & Design

Slide 3

Slide 3 text

You think you know SVG

Slide 4

Slide 4 text

I was pretty sure as well…

Slide 5

Slide 5 text

Boring & Crazy

Slide 6

Slide 6 text

Booooooooooring

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

xframeworkjs.org

Slide 15

Slide 15 text

xframeworkjs.org

Slide 16

Slide 16 text

Crazy.

Slide 17

Slide 17 text

Slide 18

Slide 18 text

(a slide with an example of train animation using SVG path) Promote with Pukhalski. Put your ad here.

Slide 19

Slide 19 text

SVG Sprites

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

.module { background: url('logo.png'); background: none, url('logo.svg'); }

Slide 23

Slide 23 text

SVG Stacks

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Clown Car Technique

Slide 27

Slide 27 text

How do you serve responsive images?

Slide 28

Slide 28 text

! responsive image

Slide 29

Slide 29 text

! responsive image Picture Element

Slide 30

Slide 30 text

The best solution so far?

Slide 31

Slide 31 text

Clown Car Technique • SVG • Media-queries • Background images

Slide 32

Slide 32 text

SVG Support

Slide 33

Slide 33 text

MQ inside SVG

Slide 34

Slide 34 text

! Clown Car Technique !

Slide 35

Slide 35 text

svg { background-size: 100% 100%; background-repeat: no-repeat; } ! @media screen and (max-width: 400px) { svg { background-image: url("images/small.png"); } } ! @media screen and (min-width: 401px) and (max- width: 700px) { svg { background-image: url(images/medium.png); } } !

Slide 36

Slide 36 text

} ! @media screen and (min-width: 401px) and (max- width: 700px) { svg { background-image: url(images/medium.png); } } ! @media screen and (min-width: 701px) and (max- width: 1000px) { svg { background-image: url(images/big.png); } } ! @media screen and (min-width: 1001px) { svg { background-image: url(images/huge.png);

Slide 37

Slide 37 text

preserveAspectRatio="xMidYMid meet"> ! Clown Car Technique ! svg { background-size: 100% 100%; background-repeat: no-repeat; } ! @media screen and (max-width: 400px) { svg { background-image: url("images/small.png"); } } ! @media screen and (min-width: 401px) and (max- width: 700px) { svg {

Slide 38

Slide 38 text

Embedding SVG • inline • img / image • object

Slide 39

Slide 39 text

Embedding inline • 1 HTTP Request • Safari and Chrome have a bug with support of preserveAspectRatio

Slide 40

Slide 40 text

Img • 2 HTTP Requests • Cleaner markup • Most browsers have content security issues with loading images

Slide 41

Slide 41 text

Object • 2 HTTP Requests • No issues with content security • preserveAspectRatio supported • Media-queries will react to parent container changes!

Slide 42

Slide 42 text

Old Browsers? ! ! “Medium" !

Slide 43

Slide 43 text

Old Browsers?

Slide 44

Slide 44 text

Single HTTP request?

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Accessibility • Add and to your SVG • Add ARIA and and other aria attributes • Add • Add attribute to fallback images • Add text inside object tag tab-index="0" role="img" alt object title description

Slide 49

Slide 49 text

Drawbacks • Browser Support • Tricky

Slide 50

Slide 50 text

Benefits • CSS is incapsulated within SVG • Simplest solution for responsive images • Already works!

Slide 51

Slide 51 text

Rethinking Responsive SVG

Slide 52

Slide 52 text

Responsive SVG. The Hobo’s Method

Slide 53

Slide 53 text

Responsive Icons (SVG)

Slide 54

Slide 54 text

Responsive Icons (SVG)

Slide 55

Slide 55 text

Responsive Icons (SVG)

Slide 56

Slide 56 text

Responsive Icons (SVG)

Slide 57

Slide 57 text

Responsive Icons (SVG)

Slide 58

Slide 58 text

.icon { width: 300px; height: 300px; background: url(../images/ home_sprite.svg); background-position: center top; } Responsive Icons (SVG)

Slide 59

Slide 59 text

@media only screen and (min-width: 65em) and (min-height:40em) { ! .icon {background-position: center -2400px;} ! } Responsive Icons (SVG)

Slide 60

Slide 60 text

@media only screen and (min-width: 60em) and (min-height:37em) { ! .icon {background-position: center -2100px;} ! } @media only screen and (min-width: 55em) and (min-height:33em) { ! .icon {background-position: center -1800px;} ! } @media only screen and (min-width: 50em) Responsive Icons (SVG)

Slide 61

Slide 61 text

Drawbacks • External CSS • 8 different illustrations • Can we make something more efficient than this technique from 90s?

Slide 62

Slide 62 text

So… • SVG can contain styles inside • SVG supports media-queries • SVG can react to the parent container size

Slide 63

Slide 63 text

Responsive SVG. The Poor Man’s Method

Slide 64

Slide 64 text

Removing margins

Slide 65

Slide 65 text

! !

Slide 66

Slide 66 text

/* Hide all of the icons first. */ .icon { display: none; } ! /* Display the first one. */ #home_icon_0 { display: block; } ! ! ! !

Slide 67

Slide 67 text

Hiding all icons except the first one

Slide 68

Slide 68 text

} ! /* Display the desired icon and hide the others according to the viewport's size. */ @media screen and (min-width: 25em) { ! #home_icon_0 { display: none; } ! #home_icon_1 { display: block; } } ! @media screen and (min-width: 30em) { #home_icon_1 { display: none; }

Slide 69

Slide 69 text

#home_icon_1 { display: block; } } ! @media screen and (min-width: 30em) { #home_icon_1 { display: none; } ! #home_icon_2 { display: block; } } ! /* And so on */ !

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

Responsive SVG. The Man With A Gun’s Method

Slide 80

Slide 80 text

What means responsive?

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Thinking about “responsive”, we imagine content choreography first.

Slide 83

Slide 83 text

Before After Redrawing icon manually

Slide 84

Slide 84 text

! ! ! ! icon Created with Sketch (http://www.bohemiancoding.com/sketch)

Slide 85

Slide 85 text

! #door-body { fill: white; } ! #door-handle { fill: #E55C3C; } ! #door-body, #door-handle { -ms-transform: translate(0,0); -webkit-transform: translate(0,0); transform: translate(0,0); } !

Slide 86

Slide 86 text

translate(0,0); transform: translate(0,0); } ! #window { -ms-transform: translate(0,0) scale(1); -webkit-transform: translate(0,0) scale(1); transform: translate(0,0) scale(1); } ! #house-body { -ms-transform: scaleX(1) translate(0, 0);

Slide 87

Slide 87 text

translate(0,0) scale(1); transform: translate(0,0) scale(1); } ! #house-body { -ms-transform: scaleX(1) translate(0, 0); -webkit-transform: scaleX(1) translate(0, 0); transform: scaleX(1) translate(0, 0); } ! #tube-body { -ms-transform: translate(0,

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

Adapting to parent container size

Slide 90

Slide 90 text

8 containers with different size. ! One and the same SVG file.

Slide 91

Slide 91 text

Browser Support • Internet Explorer 9+ • Firefox 17+ • Chrome 17+ • Opera 15+ • Safari 6.0+ • Safari on iOS 6.0+ • Android browser on Android 3.0+

Slide 92

Slide 92 text

Benefits • CSS is incapsulated within SVG • Truly responsive approach • File size

Slide 93

Slide 93 text

Drawbacks • Difficult to create and maintain • Browser support

Slide 94

Slide 94 text

SVG as a module

Slide 95

Slide 95 text

What if… • Add JavaScript logic into SVG file? • AMD/LMD for SVG? • SVG-based UI? • … • Do you still think I’m OK?

Slide 96

Slide 96 text

Search. Explore. Investigate. Share. @pukhalski