Design an adaptive-column carousel whose layout adjusts based on imported images or logos, with customization options accessible directly from the interface.
Hey @ThomC,
designing a slider where every slide can have a different size, is not a great UX and will most likely make your responsive work much harder.
My recommendation would be to set the slide width to a consistent width and set the width of the image to it.
If you want to make it much easier, use a library like swiper, splide and such as a base and go from there.
For a fully customization option for the visitor (like a demo), you’ll need to create a bunch of JS which will actually modify the embeded/used code.
If you want the page editor (HubSpot user) to have some config options, create some functions in the custom module.
For example:
Splide has many options
The regular code looks like this:
<script>
new Splide( '.splide', {
perPage: 3,
perMove: 1,
drag: true,
} );
</script>
with HubL functions it would look like this (written in the module.html)
{% require_js %}
<script>
new Splide( '.splide', {
perPage: {{module.slider_settings.per_page}}, //this is a number function
perMove: {{module.slider_settings.per_move}}, //this is a number function
drag: {{module.slider_settings.enable_drag}}, // this is a boolean
} );
Hope this helps
Best,
Anton
Hello Anton,
Thanks for your reply ![]()
Could you in that case give me some code that would ensure the spacing is identical even though our logos are not the same width?
I have the following HTML code:
{% set heading = module.heading_level|default("h2", true) %}
{% if heading not in ["h1", "h2", "h3", "h4", "h5", "h6"] %}
{% set heading = "h2" %}
{% endif %}
{% if module.title or (module.add_subtitle and module.subtitle) %}
{% if module.title %}
<{{ heading }}
class="ls__title{% if module.style.title.modify_title_position %} ls__title-{{ module.style.title.title_position|escape_attr }}{% endif %}"
>
{{ module.title }}
</{{ heading }}>
{% endif %}
{% if module.add_subtitle and module.subtitle %}
<div class="ls__subtitle">
{{ module.subtitle }}
</div>
{% endif %}
</div>
{% endif %}
{% for item in module.sliders %}
{% for image in item.images %}
{% if image.src %}
{% set imageWidth = image.width|int %}
{% set imageHeight = image.height|int %}
{% set maxWidth = image.max_width|int %}
{% set maxHeight = image.max_height|int %}
<li class="glide__slide ls__slider-list-item">
<img
class="ls__slider-list-item-image"
src="{{ image.src|escape_url }}"
alt="{{ image.alt|escape_attr }}"
{% if imageWidth > 0 %}
width="{{ imageWidth }}"
{% endif %}
{% if imageHeight > 0 %}
height="{{ imageHeight }}"
{% endif %}
style="
display: block;
margin: 0 auto;
object-fit: contain;
{% if image.size_type == 'auto' %}
width: auto;
height: auto;
max-width: 100%;
max-height: none;
{% elif image.size_type == 'auto_custom_max' %}
width: auto;
height: auto;
{% if maxWidth > 0 %}
max-width: {{ maxWidth }}px;
{% else %}
max-width: 100%;
{% endif %}
{% if maxHeight > 0 %}
max-height: {{ maxHeight }}px;
{% else %}
max-height: none;
{% endif %}
{% else %}
{% if imageWidth > 0 %}
width: {{ imageWidth }}px;
{% else %}
width: auto;
{% endif %}
{% if imageHeight > 0 %}
height: {{ imageHeight }}px;
{% else %}
height: auto;
{% endif %}
max-width: none;
max-height: none;
{% endif %}
"
{% if image.loading in ['lazy', 'eager'] %}
loading="{{ image.loading|escape_attr }}"
{% endif %}
>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endfor %}
And in CSS:
.ls h2 {
margin-bottom: 40px;
padding: 0 20px;
}
/* Center the logos within the columns */
.ls li.glide__slide.ls__slider-list-item {
display: flex;
align-items: center;
justify-content: center;
}
/* Common height and proportional width */
.ls li.glide__slide.ls__slider-list-item img {
display: block;
height: 26px !important;
width: auto !important;
max-height: none !important;
max-width: 100%;
margin: 0 auto;
object-fit: contain;
}
The equal spacing problem usually comes from the images overriding the slide size. Glide already sizes every slide itself: width = (track width minus the gaps) divided by perView, so the spacing stays identical if you let it do that and only control the image inside the slide. Set the spacing with the gap option, for example new Glide(‘.glide’, { type: ‘carousel’, perView: 4, gap: 24 }).mount(). Then in your CSS make each li a flex box with align-items: center and justify-content: center, and give the img max-width: 100%, max-height: 80px, width: auto, height: auto, object-fit: contain. In your module the auto and fixed size branches set inline width and max-width: none, which is what makes wide logos push the layout. Keep the inline size only for the max values and let the slide box stay constant.
Hi @aldo_quantic,
Thanks also for these details; I’ve just applied these codes, and indeed, they improve the spacing much better.
Since I’m not sure if I can do any better, I’ll leave it as is ![]()
A huge thank you to both of you (including @Anton)