D
D
Denis Bukreev2017-10-04 13:31:41
JavaScript
Denis Bukreev, 2017-10-04 13:31:41

How to fix animation performance?

So it goes.
There is an animation code:

if ( $('.landing__superdesign').length ) {
        let f = $('.landing__superdesign-f');
        let s = $('.landing__superdesign-s');
        let t = $('.landing__superdesign-t');

        let parallax = () => {
            let scrollTop = $('.wrap').scrollTop();
            f.css('transform', 'translateY(' + scrollTop/10 + 'px)');
            s.css('transform', 'translateY(' + -scrollTop/10 + 'px)');
            t.css('transform', 'rotate(' + (45 + scrollTop/10) + 'deg)');
            window.requestAnimationFrame(parallax);
        };
        window.requestAnimationFrame(parallax);
    }

three elements, two move vertically, one rotates around its axis (the elements are simple shapes: two rectangles and a line)
But as soon as I start scrolling the page, the macbook turns on the coolers, heats up and the page lags a bit.
In addition to this animation, there is almost the same one for the background image - it moves horizontally using backgriund-position. Without animated figures, the page does not freeze, with figures the pain already begins.
What is wrong and how to facilitate animation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2017-10-04
@denisbookreev

Why spin this function 60 times per second? It is impossible to hang up on some kind of scrolling event or the like? The parameters don't seem to change.
like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question