Hi there, so for the past few hours i’ve been trying to figure out how to get this code to work. I know absolutely nothing about code so i went to ChatGPT for help (i know…). They have somewhat created a foundation for the code, however it isn’t working correctly at all.
I’m trying to create an endless loop of logos which appear “infinite” and scroll forever. However right a few sets of logos appear in the middle of the screen, they just scroll off to the left leaving a big gap of white, then they re-appear again.
Any help is very appreciated!
CODE - - - - - - - -
{% schema %}
{
"name": "Infinite Logo Scroller",
"settings": [
{
"type": "image_picker",
"id": "logo_1",
"label": "Logo 1"
},
{
"type": "range",
"id": "logo_1_size",
"label": "Logo 1 Size",
"default": 100,
"min": 50,
"max": 300,
"step": 5
},
{
"type": "image_picker",
"id": "logo_2",
"label": "Logo 2"
},
{
"type": "range",
"id": "logo_2_size",
"label": "Logo 2 Size",
"default": 100,
"min": 50,
"max": 300,
"step": 5
},
{
"type": "image_picker",
"id": "logo_3",
"label": "Logo 3"
},
{
"type": "range",
"id": "logo_3_size",
"label": "Logo 3 Size",
"default": 100,
"min": 50,
"max": 300,
"step": 5
},
{
"type": "range",
"id": "logo_spacing",
"label": "Logo Spacing (px)",
"default": 10,
"min": 0,
"max": 50,
"step": 1
},
{
"type": "range",
"id": "animation_speed",
"label": "Animation Speed (seconds)",
"default": 10,
"min": 1,
"max": 30,
"step": 1
},
{
"type": "color",
"id": "background_color",
"label": "Background Color",
"default": "#ffffff"
}
],
"presets": [
{
"name": "Infinite Logo Scroller",
"category": "Custom"
}
]
}
{% endschema %}
<div class="infinite-logo-scroller" style="background-color: {{ section.settings.background_color }};">
<div class="logo-track">
{% for i in (1..2) %}
{% for j in (1..3) %}
{% assign logo_key = 'logo_' | append: j %}
{% assign logo_size_key = 'logo_' | append: j | append: '_size' %}
{% assign logo = section.settings[logo_key] %}
{% assign logo_size = section.settings[logo_size_key] %}
{% if logo != blank %}
<div class="logo-slide" style="width: {{ logo_size }}px; margin-right: {{ section.settings.logo_spacing }}px;">
<img src="{{ logo | img_url: '200x' }}" alt="Brand logo {{ j }}" style="width: 100%; height: auto;">
</div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
</div>
<style>
.infinite-logo-scroller {
overflow: hidden;
width: 100%;
position: relative;
}
.logo-track {
display: flex;
animation: scroll {{ section.settings.animation_speed }}s linear infinite;
}
.logo-slide {
flex: 0 0 auto;
}
@keyframes scroll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-50%);
}
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
var track = document.querySelector('.logo-track');
var logoSlides = document.querySelectorAll('.logo-slide');
var totalWidth = 0;
logoSlides.forEach(function (slide) {
totalWidth += slide.offsetWidth + parseInt(window.getComputedStyle(slide).marginRight);
});
// Set the width of the track to be twice the total width of the logos to ensure seamless scrolling
track.style.width = totalWidth * 2 + 'px';
// Adjust the duration of the animation based on the total width and the desired animation speed
var duration = totalWidth / (track.offsetWidth / {{ section.settings.animation_speed }});
track.style.animationDuration = duration + 's';
});
</script>