S
S
skolzage2020-06-08 17:55:35
JavaScript
skolzage, 2020-06-08 17:55:35

A class is added on the scroll event, do I need to add a check for the presence of a class?

Hello! A class is added on the scroll event, is it necessary to add a check for the presence of a class so that the logic of adding it is disabled and does not work every scroll? I looked in the inspector at the moment of scrolling, it seems like there are no signs of class overwriting, but this is not accurate. How is it correct?

2. Is it normal practice to add multiple scroll handlers in different functions? It is not always convenient to shove functions into one handler.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-06-08
@hzzzzl

On the scroll event, a class is added, whether it is necessary to add a check for the presence of a class so that the logic of adding it is disabled and does not work every scroll

you can just remove the event handler when it finishes

otherwise, I think that it is not necessary to check and you can just write div.classList.add('className'), the same thing will not be added twice

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question