Animierte Proteinankerverbindung

Großes Bild in HTML

In diesem Artikel wird erläutert, wie Sie Volumenelemente der Animation mit einer Webseite verbinden und nicht alles auf einmal beschädigen.


Wenn Sie sich große Sorgen über die Leistung von Google Page Speed ​​bei der Entwicklung von Websites machen und diese für jedes zusätzliche Kilobyte brennt, sollten Sie diesen Artikel nicht weiter lesen.


Diejenigen, die keine Angst vor der Größe haben und das Risiko lieben, bitte ich um einen Schnitt;)


Geschäftliche Herausforderung


, .
, . .


, , :


  1. gif . , … ?!


    , , , , (gif 256 ), 19, .

  2. , . APNG. png , IE11 . , (17) . . gif, .

  3. , !?
    , 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> 
    

  4. , . :
    animation-timing-function: steps(…)
    , , .;

( . «sequence» (, )), - – . , , .


, , .




, ( ).


– , , gulp

gulp.spritesmith

, Toptal, Chris Coyier .


. padding- 0, “Choose files” .

! ;
! .

, .


CSS Sprites Generator

, , , . ( - , , ).


, .
> 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 , , .


, , .


Natürlich ist dieses Element dekorativer Natur, was bedeutet, dass es zuletzt vom Browser gerendert werden sollte. Daher platzieren wir es näher am Ende des Dokuments. Ich möchte auch nicht sehen, wie sich das Laden eines großen Bildes auswirkt.



Um diesen Effekt zu vermeiden, stellen Sie den Wrapper-Block im Anfangsstadium so ein, dass Folgendes angezeigt wird: none; und nur wenn das Bild geladen wurde, zeigen Sie es dem Benutzer. Der Code sieht ungefähr so ​​aus.


HTML
<div class="wrapper">
  <div class="myAnimation"></div>
  <p> !</p>
</div>

CSS
body {
  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;
}

Js
awaitBgImgLoad();
function awaitBgImgLoad() {
  var div = document.querySelector('.myAnimation');
  var src = window.getComputedStyle(div).backgroundImage;
  console.log(src); //     `url("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);
}


Irgendwo vor dem Ankerlink, höher zum Hauptinhalt.

, “” src, background-image . ( img , background-image)
* , , .


Netgame Entertainment .


Logo NetGame Entertainment


Netgame Entertainment , .

OPTIMUS PRIME .



web .

All Articles