Task: to make a roulette in a casino, which will throw out a prize. In fact, this is a fast endless carousel.
The fact is that in the fox it hangs hard for 500-1000ms due to garbage collection.
How can this problem be solved?
Maybe there are ready-made similar plugins? Because I still have to write a smooth stop on the desired pre-selected element, which I have no idea how to do at all, I would like to save time.
var $carousel = $('#carousel'); var slideWidth = 500; var prigress = 0; setInterval(function() { prigress -= 50; $carousel.css({ left: prigress }); if (prigress % slideWidth == 0) { $('.slide:last').after($('.slide:first')); $carousel.css({ left: 0 }); prigress = 0; } }, 13); body { background: #333; color: #fff; } .wrap { position: relative; width: 900px; height: 300px; } .window { overflow: hidden; position: relative; background: #222; } #carousel { width: 10000px; position: relative; top: 0; left: 0; } .slide { height: 300px; width: 500px; float: left; display: flex; flex-direction: column; justify-content: center; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="wrap"> <div class="window"> <div id="carousel"> <span class="slide" id="b1">SLIDE-1</span> <span class="slide" id="b2">SLIDE-2</span> <span class="slide" id="b3">SLIDE-3</span> <span class="slide" id="b4">SLIDE-4</span> <span class="slide" id="b5">SLIDE-5</span> </div> </div> </div>