El artículo discutirá cómo conectar elementos de volumen de animación a una página web y no dividir todo de una vez.
Si está muy preocupado por el rendimiento de Google Page Speed en el desarrollo de sitios y se quema por cada kilobyte adicional, no debe continuar leyendo este artículo.
Aquellos que no tienen miedo al gran tamaño y aman el riesgo, pido un corte;)
Desafío de negocio
, .
, . .
, , :
— gif . , … ?!
, , , , (gif 256 ), 19, .
, . APNG. png , IE11 . , (17) . . gif, .
- , !?
, mp4 . , , , .
mp4 , , , .
, .
, video.
.
<video class="bl_video" loop="" muted="" autoplay="" poster="poster.jpg">
<source src="topbanner.webm" type="video/webm">
<source src="topbanner.mp4" type="video/mp4; codecs="avc1.42E01E, mp4a.40.2"">
</video>
- , . :
animation-timing-function: steps(…)
, , .;
— ( . «sequence» (, )), - – . , , .
, , .
, ( ).
– , , gulp
gulp.spritesmith, Toptal, Chris Coyier .
. padding- 0, “Choose files” .
! ;! ., .
, , , . ( - , , ).
, .
> 5, .
png . (7,92)
, . ( TinyPNG Squoosh)
, gulp-imagemin –
« , .»
, , , .
, , . , , 25-40 .
1.2 , .
, , , - . CSS , . .
.toContactForm_leprechaun {
width: 220px;
height: 290px;
box-sizing: border-box;
background: url(../image/leprechaun-sprite.png) 0 50%;
animation: play 3276ms steps(91) infinite;
}
@keyframes play {
to {
background-position: -20020px;
}
}
, , .
1) width height (, width height).
2) — Y.
3) . , .
* .
steps .
, , 30 – 45 .
4) .
= (-1px)* *width .
* , . .
. .
, . , 100, .
body , DOM , .
, .
*, , Performance Google Lighthouse 80 20 .
5G , Neuralink - .
, 91 73. (5,17), , , Squoosh ( - <16300px)
, IE , Safari, ?
. webP
( 2,47 Squoosh , 1,67, , );
* window.navigator.userAgent, png , , .
, , .
Por supuesto, este elemento es de naturaleza decorativa, lo que significa que debe ser procesado por el navegador al final. Por lo tanto, lo colocamos más cerca del final del documento. Tampoco quiero ver el efecto de cargar una imagen grande.
Para evitar este efecto, configure el bloque de envoltura en la etapa inicial para mostrar: ninguno; y solo cuando la imagen se haya cargado, muéstresela al usuario. El código se parece a esto.
HTML<div class="wrapper">
<div class="myAnimation"></div>
<p> !</p>
</div>
CSSbody {
margin: 0;
}
.wrapper {
display: none;
padding: 10px;
border: 1px solid #000;
}
.wrapper.active {
display: block;
}
.myAnimation {
display: inline-block;
width: 247px;
height: 187px;
background: url("https://gyazo.com/f5d013014306342a2241f8d3b8fb11ea.png") 50% 50% no-repeat;
}
p {
display: inline-block;
width: 150px;
vertical-align: top;
}
JsawaitBgImgLoad();
function awaitBgImgLoad() {
var div = document.querySelector('.myAnimation');
var src = window.getComputedStyle(div).backgroundImage;
console.log(src);
src = src.replace(/url\(|\)|"/g,"")
loadAndRun(src, onload);
function onload() {
console.log(" !");
document.querySelector('.wrapper').style.display = "block";
}
}
function loadAndRun(src, resolve, reject) {
var img = new Image();
img.onload = resolve;
img.onerror = reject || function(){
console.log(" " + src)
};
img.src = src;
}
( , ), ‹head›
<link rel="preload" href=" bigAnimationImg.webP" as="image" />
JS, :
<img class="animation-image" width="220" height="290" src="bigAnimationImg.webP" loading="eager" alt="animation"/>
.animation-image{
position:absolute;
top:0;
left:calc(-100%+1px);
}
En algún lugar frente al enlace de anclaje, más alto que el contenido principal., “” src, background-image . ( img , background-image)
* , , .
Netgame Entertainment .
Netgame Entertainment , .
OPTIMUS PRIME .
web .