BACK ⟲
Scris de Marius Chiriac

Animatie JS si CSS pentru prezentarea de continut la scroll

La INOVEO intotdeauna cautam metode inovative si frumoase de a crea website-uri moderne si dinamice. Experimentarea in crearea de animatii CSS si JS este ceva ce eu fac saptamanal pentru a ma familiariza cu tehnologii noi sau sa invat sa creez lucruri ce mi-au placut la alte website-uri.

In acest articol vom crea animatii legate la scroll de pagina pentru a face “reveal” la continutul paginii incarcate sau a unei sectiuni din pagini. La final veti putea vedea rezultatul si veti putea citi codul sursa scris intr-un codepen.

1. Codul HTMl este unul simplu in care vom avea un wrapper ce va fi folosit in setarea inaltimea sectiunii cu un div pozitionat fixed ce va contine contentul si elementele ce le vom anima.

In acest caz am ales un supergrafic de forma unui dreptunghi creat prin CSS, dar acesta poate fi inlocuit cu un SVG sau alt timp de element. In partea superioara am adaugat un div ce va creste de la 0 la 100% in lungime ce va reprezenta pozitia scroll-ului in pagina.

2. Codul CSS va fi folosit pentru stilizare, pozitionare si stabilirea dimensiunilor initiale a elementelor.

3. Codul JS va detecta initial evenimentele de scroll facute in pagina. Cand se face scroll functia va prelua inaltimea paginii (setata de mine la de 2 ori inaltimea unui ecran in acest caz) si pozitia scroll-ului.

Cu aceste doua valori vom calcula procentajul pentru scalarea elementului “loader” pe axa X prin formula “inaltime website/inaltime ecran”. In exemplul nostru scroll-ul va fi intotdeuna maxim inaltimea ecranului, dar aceasta formula se va modifica in functie de website pentru a calcula corect procentajul.

In acelasi timp vom mari supergraficul din fata pozei astfel incat gaura din mijloc sa permita vizualizarea completa a tot ce este in spate. Inainte de finalizarea scroll-ului am adauga o animatie in care poza din background sa se mareasca putin.

Puteti sa va jucati cu aceasta animatie aici (dati scroll):

See the Pen
Cool JS and CSS animations on scroll
by Puiu (@Puiu)
on CodePen.

Astfel de animatii sunt foarte flexibile, adaptabile si pot fi folosite in multe moduri intr-un website. Voi mai prezenta si alte tipuri de animatii in viitoare articole care sper sa va inspire.

More posts

What large and small companies ask of branding

Small companies ask branding for a clear identity, while large companies ask for a system that keeps it the same in dozens of places. In the INOVEO archive, companies with revenue above 250 million lei [...]

Read More... from Animatie JS si CSS pentru prezentarea de continut la scroll

Read the post

What each industry asks of its brand

Brand accounts for 32% of the purchase decision in technology and 67% in luxury, according to Interbrand. That is why each industry asks something different of its brand, depending on where and how fast its [...]

Read More... from Animatie JS si CSS pentru prezentarea de continut la scroll

Read the post

Which branding work you do together, and in what order

Branding work delivers results when it is done as a system, in the order in which each piece supports the next: strategy first, then identity, then applications. The wrong order costs twice: an identity made [...]

Read More... from Animatie JS si CSS pentru prezentarea de continut la scroll

Read the post

Branding for companies outside Bucharest

About 73% of Romania’s economy is produced outside the capital, and the companies there have a brand argument that is hard to copy: the place they come from. In the INOVEO archive, 45% of clients [...]

Read More... from Animatie JS si CSS pentru prezentarea de continut la scroll

Read the post

INOVEO
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.