Does cyclical animation occur using browsers?

I have a PNG that moves around the screen in a repeating loop, which I believe may cause some browsers to crash.

For instance:

function parachute_drop(drop_object, animation_duration) { $(drop_object) .animate({top: "750px"},animation_duration) .animate({top:"-150px", opacity: 100 },{ duration: 0, complete: function(){ parachute_drop(drop_object,animation_duration); } }); } parachute_drop('#object_id',10000); 

Each time the animation ends, it launches the function again and to infinity.

I did not see this being problematic, but I heard that it is not very good and good, my site is now crashing after a while it seems.

Is there a way to make endless loops like this in a more stable way? It seems a little strange that just moving a 9 kilobyte PNG file up and down the screen over and over again is a strain on system resources. What is the problem and how do I approach this better?

+4
source share
1 answer

Your code is a recursive algorithm and may crash when it populates the code stack of the browser javascript machine. To achieve a continuous loop, you can use a different timer-based approach.

You can start with this example: http://www.irengba.com/codewell/

+2
source

Source: https://habr.com/ru/post/1399919/


All Articles