Creating a Product Showcase with Changing Images: The Adidas Section
Visual appeal is crucial for attracting customers and driving sales. One effective way to enhance your online store's aesthetics is by incorporating dynamic product showcases. In this blog post, we will explore how to create a Shopify section that replicates the Adidas website's product card feature, complete with changing images. This section not only looks great but also engages users by showcasing multiple product images in a seamless manner.
Code: https://github.com/ndrishinski/blogs/blob/master/adidas-changing-image/sections/adidas-images.liquid
Prefer video?
Enjoy, otherwise read on!
Overview of the Adidas Section
The Adidas section we will create consists of a grid of product cards, each featuring an image that changes at a specified interval. This design allows customers to see different angles or variations of a product without needing to click through multiple images. The section is built using Liquid, Shopify's templating language, along with HTML and CSS for styling.
Key Features
- Responsive Design: The product grid adapts to different screen sizes, ensuring a great user experience on both desktop and mobile devices.Dynamic --
- Image Switching: Each product card can display up to four images, which automatically rotate based on a defined interval.Customizable Settings:
- Store owners can easily modify the button text, image links, and other settings through the Shopify admin interface.
1. Setting Up the Section
2. HTML Structure
<div class="container" id="adidas-section">
<div class="product-grid">
{% for block in section.blocks %}
<div class="product-card">
<div class="product-image">
<div class="image-container" style="background-image: url('{{ block.settings.card_image_1 | image_url: width: 450, crop: 'center' }}');"
{% if block.settings.card_image_1 %}data-first="{{ block.settings.card_image_1 | image_url: width: 450, crop: 'center' }}"{% endif %}
{% if block.settings.card_image_2 %}data-second="{{ block.settings.card_image_2 | image_url: width: 450, crop: 'center' }}"{% endif %}
{% if block.settings.card_image_3 %}data-third="{{ block.settings.card_image_3 | image_url: width: 450, crop: 'center' }}"{% endif %}
{% if block.settings.card_image_4 %}data-fourth="{{ block.settings.card_image_4 | image_url: width: 450, crop: 'center' }}"{% endif %}
data-interval="{{ block.settings.interval }}"
></div>
</div>
<h2>{{ block.settings.card_title }}</h2>
<p>{{ block.settings.card_subheading }}</p>
<a href="collections/{{ block.settings.collection-link }}" class="shop-now">{{ section.settings.cta-button }}</a>
</div>
{% endfor %}
</div>
</div>
3. CSS Styling
#adidas-section {
max-width: 1400px;
margin: 0 auto;
padding: 2rem;
font-family: Arial, sans-serif;
background-color: #fff;
}
#adidas-section .product-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 2rem;
}
#adidas-section .product-card {
background-color: #fff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease;
}
#adidas-section .product-card:hover {
transform: translateY(-5px);
}
4. JavaScript Functionality
function initializeProductCards() {
const productCards = document.querySelectorAll('.image-container');
productCards.forEach((card) => {
const imagesArray = [
card.getAttribute('data-first'),
card.getAttribute('data-second'),
card.getAttribute('data-third'),
card.getAttribute('data-fourth')
].filter(Boolean);
let currentImageIndex = 0;
const interval = card.getAttribute('data-interval');
setInterval(() => {
card.style.backgroundImage = `url(${imagesArray[currentImageIndex]})`;
currentImageIndex = (currentImageIndex + 1) % imagesArray.length;
}, interval);
});
}
document.addEventListener("DOMContentLoaded", initializeProductCards);
5. Customization Options
