D
D
Daniil Ivanov2018-03-05 16:53:55
Layout
Daniil Ivanov, 2018-03-05 16:53:55

Are dom elements with display:none CPU-intensive?

There is a web application with a list of 1500 items, styles and animations. A bunch of transition animations. If some of the elements are hidden, will it reduce the load?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2018-03-05
@Stalker_RED

in general, yes, it will reduce, but from the fact that they are hidden, they do not become "completely free". When redrawing, they will be processed much faster than visible elements, but they still exist in memory, and when bypassed by scripts, for example, they will be taken into account. And sim3x correctly wrote - for any brakes, see the profiler.
Quite cool - check also on a weak computer. Not all visitors to your site have top-end hardware, this is especially true for phones.

X
xmoonlight, 2018-03-06
@xmoonlight

I advise you to load such lists gradually as you need to display (scroll the page, etc.) via AJAX.
And for those who are not in the viewport visibility zone, pause any animation / playback.
The "magnifying glass" mode should be used:
1. What is closer to the viewport, then "animate": along the perimeter of the real viewport, we take 1 viewport for preloading and prerendering (3x3 square, in the center - the real viewport).
2. What is further than this zone (3x3) - we generally delete the DOM from memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question