A
A
artur0120972021-03-30 23:42:59
Processors
artur012097, 2021-03-30 23:42:59

How to make animated loading of elements?

How to make a phased animation of the appearance of elements when scrolling through JS? Is it desirable without the use of ready-made libraries (but does not interfere) and that the neighboring element be fixed until the end of the animation (not necessary)?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xmoonlight, 2018-04-14
@Hutaab

2nd option.

D
Danny Arty, 2021-03-31
@DanArst

Without libraries, it is logical that you will have to write your own solution.
From the libraries there is wow.js for example

I
Ivan Kulakov, 2021-03-31
@ivankprod

You can use IntersectionObserver, for example :)

if ('IntersectionObserver' in window &&
      'IntersectionObserverEntry' in window &&
      'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
    if (!('isIntersecting' in IntersectionObserverEntry.prototype)) {
      Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
        get: function() { return this.intersectionRatio > 0; }
      });
    }

    var oObserver = new IntersectionObserver(function(entries, observer) {
      entries.forEach(function(entry) {
        if (entry.isIntersecting) {
            //  делаем анимацию (добавляем css-класс в котором настроены анимации)
            entry.target.classList.add('animate');
        }
      });
    });

    // вешаем observer на массив элементов
    arrayElements.forEach(function(elem) {
      oObserver.observe(elem);
    });
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question