Vincent De Oliveira · @iamvdo
Amélioration progressive
Progressive enhancement
Quelles solutions ?
Back to basics
.el {
/* ne rien faire */
backdrop-filter: blur(5px)
}
.el {
/* fallback */
display: flex;
display: hologram;
}
@supports
@supports (backdrop-filter: blur(5px)) {
.el {
backdrop-filter: blur(5px);
background: rgba(0, 0, 0, .5);
}
}
@supports (clip-path: circle()) { … }
@supports not (display: hologram) { … }
CSS can do this!
// Vanilla JS
if (CSS.supports('backdrop-filter', 'blur(5px)')) { … }
/* CSS */
.no-geolocation .box { … }
.geolocation .box { … }
// JavaScript
if (Modernizr.geolocation) { … }
@supports
/CSS.supports
Can I Use css-featurequeries? Data on support for the css-featurequeries feature across the major browsers from caniuse.com.
C’est compliqué !
Mais ça c’était avant !
.el {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background: gray;
}
.item {
flex: 0 1 auto;
width: 100px;
height: 50px;
}
//
.item:nth-child(2) {
order: 1;
background: deeppink;
}
.Site {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.Site-content {
flex: 1;
}
vw
, vh
: relatif au viewport, %
: relatif au containing block
.Field {
display: flex
}
.Field input {
flex: 1
}
.Field label {
width: 100px
}
.Site {
display: flex
}
.Box {
margin: auto
}
.Site {
display: flex;
justify-content: center;
align-items: center
}
Can I Use flexbox? Data on support for the flexbox feature across the major browsers from caniuse.com.
Flexibility (Polyfill IE9-)
Mieux que Flexbox ?
Grid Layout
.el {
display: grid;
grid-template-columns: 100px 1fr;
grid-template-rows: 50px 1fr 50px;
}
.item:nth-child(1) {
grid-column: 1 / span 2;
grid-row: 1;
}
.item:nth-child(2) {
grid-column: 1;
grid-row: 2;
background: deeppink;
}
.item:nth-child(3) {
grid-column: 2;
grid-row: 2;
background: greenyellow;
}
.item:nth-child(4) {
grid-column: 1 / span 2;
grid-row: 3;
}
Idée de layout par Wes Bos
.Site {
display: grid;
grid-template-columns: repeat(7);
grid-template-rows: repeat(7);
grid-template-areas:
". a . . . . ."
"g a f f f f ."
"g a f f f f ."
"g d d e e e e"
"g d d b b c ."
"h d d b b c ."
". d d . . c .";
}
.item1 { grid-area: a }
.item2 { grid-area: b }
.item3 { grid-area: c }
.item4 { grid-area: d }
.item5 { grid-area: e }
.item6 { grid-area: f }
.item7 { grid-area: g }
.item8 { grid-area: h }
Can I Use css-grid? Data on support for the css-grid feature across the major browsers from caniuse.com.
Firefox et Chrome/Opera : supporté par un flag
Ça va arriver très vite !
linear
, ease
, ease-in
, ease-out
, ease-in-out
cubic-bezier()
.transition {
transition: margin-left 2s;
}
.transition-parent:hover .transition {
margin-left: 150px;
}
.animation-parent:hover .animation {
animation: demo-anim 2s infinite alternate;
}
@keyframes demo-anim {
0% {
margin-left: 0;
background: deeppink;
}
100% {
margin-left: 150px;
background: deepskyblue;
}
}
La solution : JavaScript !
Objectif : des animations JS aussi performantes que des animations CSS
requestAnimationFrame
requestAnimationFrame
function animate() {
// Animations !
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
La plupart des librairies d’animations JS utilisent requestAnimationFrame
var elem = document.querySelector('div');
elem.animate({
opacity: [0.5, 1],
transform: ['scale(0.5)', 'scale(1)'],
}, {
direction: 'alternate',
duration: 500,
iterations: Infinity,
});
Can I Use web-animation? Data on support for the web-animation feature across the major browsers from caniuse.com.
animate({
el: "div",
translateY: 100,
scale: 1.4,
duration: 500,
delay: 1000,
easing: "easeOutElastic",
loop: true,
direction: "alternate",
begin: () => {},
complete: () => {}
});
Bon
Moins bon
Transformations + Animations = Full Power!
.transform {
transform: rotate(0deg);
transition: transform 1s;
}
C’est pas juste un gadget
Hardware Accelerated
= bon pour les perfs d’affichage
COMPOSITE FTW!
transform
, opacity
top
/left
/right
/bottom
/margin
translate()
width
/height
scale()
display
/visibilité
opacity
box-shadow
opacity
/transform
Et pas que votre super PC/Mac
Votre mobile aussi !
requestAnimationFrame
transition
/animation
Ecran faible densité vs. écran haute densité
1px CSS != 1px écran
Icones vectorielles
@font-face
@font-face {
font-family: myIcons; src: url(myIcons.woff);
}
.element { font-family: myIcons; }
<svg viewBox="0 0 100 100">
<circle cx="50" cy="50" r="50" fill="yellow" />
<rect width="50" height="50" x="50" y="50" fill="blue" />
</svg>
Icon-font | SVG | |
---|---|---|
Création | ||
Intégration | ||
Support | ||
Fallback | ||
Sprites |
Icon-font | SVG | |
---|---|---|
CSS, Positionnement | ||
Interactions/animations | ||
JavaScript | ||
RWD | ||
Accessibilité |
SVG everywhere!
Remettez en cause tout ce que je viens de vous montrer
Soyez critique. Toujours. Tout le temps.