-
0754ben84
Hi guys, I’ve got an image carousel on my page but there’s a massive gap between the images and the control.
You can see it here:
https://lincolnshireseo.com/case-studies/lincolnshire-security-systems/
When you scroll a few times, the gap disappears and the whole thing works as it should. I can’t find a fix for it.
Any ideas?
Here’s a video: https://www.loom.com/share/5660cc59de6546899f9d42dc803728a6
Thanks
-
George
Hello,
The gap is caused by a conflict between SiteGround Optimizer’s lazy loading and your carousel. When the page loads, the carousel initialises before the images have loaded — so it calculates its height based on the placeholder (a 1×1px transparent GIF), leaving a large empty space. Once the real images load, the height never gets recalculated unless you interact with the carousel, which is why scrolling through it a few times makes the gap disappear.
The fix is a small script that listens for each carousel image finishing loading and then tells the carousel to recalculate its height.
- Go to Appearance → Elements → Add New Element
- Create a new Hook Element and set the hook to
wp_footer - Set the display rules so it only loads on the relevant page
- Add a Code block and paste in the following:
<script> document.addEventListener('DOMContentLoaded', function () { var interval = setInterval(function () { var carouselEl = document.querySelector('.gb-carousel-2476ad6f'); if (!carouselEl) return; var swiperInstance = carouselEl.swiper; if (!swiperInstance) return; clearInterval(interval); document.addEventListener('lazyloaded', function (e) { if (carouselEl.contains(e.target)) { swiperInstance.updateAutoHeight(); swiperInstance.update(); } }); }, 100); }); </script>Let me know how you get on.
-
0754ben84
OK I’ve done that but now it displays a scroll bar on the right side which disappears after scrolling a few times:
https://lincolnshireseo.com/case-studies/lincolnshire-security-systems/
Also, what if I want to use carousels across the site as this only fixes one carousel one page?
Thanks
-
George
Hello,
It seems the script I provided creates more issues. Please, remove the script and get in touch with SiteGround support regarding their optimizer. They will be able to help.
- You must be logged in to reply to this topic.