Struggling with a JavaScript code issue. The Logo marquee suddenly jumps at the end of each loop:
I've tried everything, but I can't seem to fix it and make it work as intended
Here's the complete script that technically works, but causes the animation to jump at a certain point.
<!DOCTYPE html>
<html>
<head>
<title>Vertical Logo Marquee</title>
<style>
.marquee-container {
height: 200px;
/* Adjust height as needed */
overflow: hidden;
position: relative;
}
.marquee-list {
position: absolute;
top: 0;
width: 100%;
height: auto;
/* Change height to auto */
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
/* Add flex-direction: column */
gap: 12px;
/* Add gap between items */
}
.marquee-list li {
height: 150px;
/* Change the height of list items */
display: flex;
align-items: center;
background-color: red;
}
.marquee-list li img {
max-height: 100%;
max-width: 100%;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="marquee-container">
<ul class="marquee-list">
<li><img src="logo1.png" alt="Logo 1"></li>
<li><img src="logo2.png" alt="Logo 2"></li>
<li><img src="logo3.png" alt="Logo 3"></li>
<li><img src="logo4.png" alt="Logo 4"></li>
<li><img src="logo5.png" alt="Logo 5"></li>
</ul>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
var marqueeContainer = $(".marquee-container");
var marqueeList = $(".marquee-list");
var marqueeItems = $(".marquee-list li");
var marqueeHeight = marqueeContainer.height();
var itemHeight = marqueeItems.outerHeight(true); // Include margin in height calculation
var gap = 12; // Gap between items
var totalHeight = (itemHeight + gap) * marqueeItems.length - gap; // Adjusted total height
var topValue = 0;
// Duplicate marquee items to create a continuous loop
marqueeItems.clone().appendTo(marqueeList);
function moveMarquee() {
topValue -= 1;
if (topValue < -totalHeight) {
topValue = 0;
}
marqueeList.css("top", topValue);
}
var marqueeInterval = setInterval(moveMarquee, 20);
// Pause marquee on hover
marqueeContainer.on("mouseenter", function () {
clearInterval(marqueeInterval);
}).on("mouseleave", function () {
marqueeInterval = setInterval(moveMarquee, 20);
});
});
</script>
</body>
</html>
Seeking help from anyone who can provide insight into what might be causing this issue or offer a solution.