Shopify themes, liquid, logos, and UX
Hello,
I got a question. Is it possible to add scroll bar in my product slider. Becuse I’m my theme it’s not possible. I need scroll like on the example
Like when you scrolling it’s increasing size to the right
Hi Aleksander22 , our team will help you ,
Locate the Slider Code: Find the section in your Shopify theme where the product slider is implemented. This could typically be in sections or snippets, such as product-slider.liquid or something similar.
Wrap the Slider with a Scrollable Container: Add a wrapper around your slider with overflow-x: auto to enable horizontal scrolling. This can be done by modifying the Liquid file where the slider is coded.
Add CSS for the Scrollbar: You need to add some CSS to make the container scrollable and style the scrollbar if needed.
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
hey , Thanks for reaching out ,
{% comment %}
Product Slider Section
{% endcomment %}
<div class="scrollable-slider-container">
<div class="product-slider">
{% assign products = collections['your-collection-handle'].products %}
{% for product in products %}
<div class="product-card">
<!-- Product Image -->
<a href="{{ product.url }}" class="product-image">
<img src="{{ product.featured_image | img_url: 'medium' }}" alt="{{ product.title }}">
</a>
<!-- Product Title -->
<div class="product-title">
<a href="{{ product.url }}">{{ product.title }}</a>
</div>
<!-- Product Price -->
<div class="product-price">
{{ product.price | money }}
</div>
</div>
{% endfor %}
</div>
</div>
Replace 'your-collection-handle' with the handle of the collection you want to display. You can find this handle in the Collections section of your Shopify admin.
Next, you need to add the CSS code to make the slider scrollable. Follow these steps:
.scrollable-slider-container {
overflow-x: auto;
white-space: nowrap;
-webkit-overflow-scrolling: touch; /* Enables smooth scrolling on iOS devices */
margin: 0 auto; /* Centers the slider on the page */
padding: 20px 0; /* Adds padding around the slider */
}
.product-slider {
display: inline-block; /* Keeps the slider content in a single line */
width: max-content; /* Ensures the slider's width fits all product cards */
}
.product-card {
display: inline-block; /* Displays product cards side by side */
width: 200px; /* Adjust width as needed */
margin-right: 10px; /* Space between each product card */
box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* Adds a subtle shadow */
background-color: #fff; /* Background color for each card */
border-radius: 5px; /* Rounded corners for cards */
overflow: hidden; /* Ensures content doesn't overflow the card */
text-align: center; /* Centers text within each product card */
padding: 10px; /* Adds padding inside each card */
}
/* Optional: Custom scrollbar styles */
.scrollable-slider-container::-webkit-scrollbar {
height: 8px; /* Height of horizontal scrollbar */
}
.scrollable-slider-container::-webkit-scrollbar-thumb {
background-color: #888; /* Scrollbar thumb color */
border-radius: 10px; /* Rounded scrollbar thumb */
}
.scrollable-slider-container::-webkit-scrollbar-thumb:hover {
background-color: #555; /* Hover color for scrollbar thumb */
}
To make the slider more interactive with a drag-to-scroll feature, add Javascript:
document.addEventListener('DOMContentLoaded', function () {
const slider = document.querySelector('.scrollable-slider-container');
let isDown = false;
let startX;
let scrollLeft;
slider.addEventListener('mousedown', (e) => {
isDown = true;
slider.classList.add('active');
startX = e.pageX - slider.offsetLeft;
scrollLeft = slider.scrollLeft;
});
slider.addEventListener('mouseleave', () => {
isDown = false;
slider.classList.remove('active');
});
slider.addEventListener('mouseup', () => {
isDown = false;
slider.classList.remove('active');
});
slider.addEventListener('mousemove', (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - slider.offsetLeft;
const walk = (x - startX) * 2; // Adjusts scroll speed
slider.scrollLeft = scrollLeft - walk;
});
});
Now that you have created the new section, you need to add it to a page or template.
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
I got a question becuse I have already product slider so can’t name this section the same. So how to name it @Hamza_takkar
ok , can you give me a collaborative access to the shop so i can check it out .
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
please also share your store URL ending with .myshopify.com
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
It’s just glovyzone.com
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
I removed the code that you send becuse I thought I’m gonna do something wrong. So you have to add code again
i have requested , please accept it so i can check it out 👍
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
I accepted it
check it in duplicate theme , it seem someone has already done it before me , while i was working on it .
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
@Hamza_takkar Yeah it was in my previous site. So can you help me to add this to my current them
ok doing it now
-Need a Shopify Specialist? Chat on
- Custom Design | Advanced Coding | Store Modifications
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024