$(document).ready(function(){ $('.prod-item').each(function(){ console.log($(this)); var val = parseInt($(this).data('prod-percent'), 10); if (val > 70) { $(this).addClass('red'); } else { $(this).addClass('green'); } }); }); $(function(){ const $track = $('#marqueeTrack'); const $set = $track.find('.set').first(); // Make two identical sets back-to-back const $clone = $set.clone(true); $track.append($clone); // Measure width of one full set (including gaps) // Use getBoundingClientRect for sub-pixel accuracy function setWidth(){ return $set[0].getBoundingClientRect().width; } let speed = 70; // px/sec let x = 0; let last = performance.now(); let running = true; let w = setWidth(); // Recalc on resize $(window).on('resize', () => { w = setWidth(); }); function step(now){ const dt = (now - last)/1000; last = now; if (running){ x -= speed * dt; if (x <= -w){ // when first set fully off-screen… x += w; // …jump back by exactly its width } $track.css('transform', `translate3d(${x}px,0,0)`); } requestAnimationFrame(step); } requestAnimationFrame(step); // Pause on hover (optional) $track.closest('.container').on('mouseenter', () => running = false) .on('mouseleave', () => running = true); });