I have been experimenting with creating a continuous strip of logos that display customer quotes when selected. I have successfully implemented functionality for selecting and displaying the logos and quotes. However, I am facing an issue with making the logos scroll infinitely.
The problem arises when the logo divs go beyond the boundaries of their container. I have been attempting to remove the logos once they reach a certain point and then recreate them on the other end of the strip. Unfortunately, this solution is not working as smoothly as I had hoped.
Below is the HTML code for the logo strip:
<div class="logo-strip">
<div id="logo-1" class="logo">
<img src="http://www.henningsen.com/wp-content/themes/henningsen-cold-storage/images/logo-emboss.png">
</div>
<div id="logo-2" class="logo">
<img src="http://www.henningsen.com/wp-content/themes/henningsen-cold-storage/images/logo-emboss.png">
</div>
<div id="logo-3" class="logo">
<img src="http://www.henningsen.com/wp-content/themes/henningsen-cold-storage/images/logo-emboss.png">
</div>
<div id="logo-4" class="logo">
<img src="http://www.henningsen.com/wp-content/themes/henningsen-cold-storage/images/logo-emboss.png">
</div>
<div id="logo-5" class="logo">
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/c/ce/Safeway_Logo.svg/1280px-Safeway_Logo.svg.png">
</div>
<div id="logo-6" class="logo">
<img src="http://www.henningsen.com/wp-content/themes/henningsen-cold-storage/images/logo-emboss.png">
</div>
<div id="logo-7" class="logo">
<img src="http://www.henningsen.com/wp-content/themes/henningsen-cold-storage/images/logo-emboss.png">
</div>
<div id="logo-8" class="logo">
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/c/ce/Safeway_Logo.svg/1280px-Safeway_Logo.svg.png">
</div>
</div>
Here is the CSS code for styling the logo strip:
div.logo-strip {
display: flex;
height: 70px;
width: 100%;
overflow: hidden; }
div.logo-strip div.logo {
display: flex;
min-width: 112.5px;
padding: 5px;
cursor: pointer;
opacity: .4;
transition: .5s; }
div.logo-strip div.logo img {
object-fit: contain; }
div.logo-strip div.selected-logo {
opacity: 1; }
Lastly, here is the JavaScript code I have been working on:
( function( $ ) {
$('div#quote-1').removeClass('hidden');
$('div#quote-1').animate({'opacity' : '1'}, 500);
$('div#logo-1').addClass('selected-logo');
$('div.logo').click(function() {
$('div.logo').removeClass('selected-logo');
$(this).addClass('selected-logo');
var logo_offset = $(this).offset().left - $('div.logo').first().offset().left;
var negative_offset = logo_offset * -1;
var strip_offset = $('div.logo-strip').offset().left - $('div.logo').first().offset().left;
if (strip_offset > 100) {
var to_be_cloned = $('div.logo').slice(0, 3);
to_be_cloned.remove();
$('div.logo').last().after(to_be_cloned);
}
console.log(strip_offset);
console.log(to_be_cloned);
$('div.logo').css({'transform' : 'translateX(' + negative_offset + 'px)'});
var logo_id = $(this).attr('id');
var logo_id_trimmed = logo_id.substr(5);
$('div.customer-quote').addClass('hidden');
$('div.customer-quote').css({'opacity' : '0'});
$('div#quote-' + logo_id_trimmed).removeClass('hidden');
$('div#quote-' + logo_id_trimmed).animate({'opacity' : '1'}, 500);
});
} )( jQuery );
I have been struggling with successfully implementing a seamless infinite scrolling feature for the logos in the strip. If anyone has any insights or solutions on how to achieve this, I would greatly appreciate it!