A
A
Aleksandr2017-05-02 14:17:41
JavaScript
Aleksandr, 2017-05-02 14:17:41

Adding elements from json?

I have already asked such a question And Sergey Sokolov
prompted me very much . As a result, I get such a hat . Now I can’t figure out how to me:

  • Remove twitching
  • Display > 2 elements in a container.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2017-05-02
@Sashjkeee

twitching is purely visual due to the fact that you repeat the iteration with two containers and end it when it is not required.
IMHO, we need to build the logic that the container instance should be a separate entity and the movement of containers should not be related to each other. The birth of the first container according to the page load, then iteration to create the container when X pixels, % or any other condition is left on the screen from the previous container. At least rivet on a timer.
Most likely the logic should be as follows:

function createBlock() {
    // получаем следующие данные из массива
    // создаем блок и заставляем его ехать. Когда он уедет желательно дестроить его из памяти.
    setTimeout(createBlock, 200); 
}

This approach will firstly solve vertical scaling, and secondly, it will save you from hemorrhoids with twitching.
setTimeout can be changed to something else, for example, take an emitter, and emit information from the instance that the block is almost invisible already and it's time to create a new one, and create a new block in the on subscription to this event. It's more convenient here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question