Carousel doesn't start working till browser resize gets to a point where the carousel needs to resize, then works as intended.
See original GitHub issueBug is related to
Embla wont init till resize is triggered.
- Vanilla 4.5.3
- ES6 Webpack Project
Embla Carousel version
- v4.5.3
Describe the bug
- Carousel doesn’t become interactive till a browser resize to the carousel’s width is triggered.
Code
- HTML
<div id="c1" class="embla embla-1">
<div class="embla__viewport">
<div class="embla__container">
<div class="embla__slide">
<div class="embla__slide__inner">
<img class="embla__slide__img" src="/assets/images/artist-pages/01-profile.jpg" />
</div>
</div>
<div class="embla__slide">
<div class="embla__slide__inner">
<img class="embla__slide__img" src="/assets/images/artist-pages/02-profile.jpg" />
</div>
</div>
<div class="embla__slide">
<div class="embla__slide__inner">
<img class="embla__slide__img" src="/assets/images/artist-pages/03-profile.jpg" />
</div>
</div>
<div class="embla__slide">
<div class="embla__slide__inner">
<img class="embla__slide__img" src="/assets/images/artist-pages/04-profile.jpg" />
</div>
</div>
<div class="embla__slide">
<div class="embla__slide__inner">
<img class="embla__slide__img" src="/assets/images/artist-pages/05-profile.jpg" />
</div>
</div>
<div class="embla__slide">
<div class="embla__slide__inner">
<img class="embla__slide__img" src="/assets/images/artist-pages/06-profile.jpg" />
</div>
</div>
</div>
</div>
</div>
- JS
const mainCarouselWrap = document.getElementById("c1");
const mainCarouselView = mainCarouselWrap.querySelector("c1 .embla__viewport");
const mainCarousel = EmblaCarousel(mainCarouselView, {
selectedClass: "",
slidesToScroll: 2,
loop: false
});
- CSS
.embla {
position: relative;
background-color: #f7f7f7;
padding: 20px;
max-width: 670px;
margin-left: auto;
margin-right: auto;
}
.embla__viewport {
overflow: hidden;
width: 100%;
}
.embla__viewport.is-draggable {
cursor: move;
cursor: grab;
}
.embla__viewport.is-dragging {
cursor: grabbing;
}
.embla__container {
display: flex;
user-select: none;
-webkit-touch-callout: none;
-khtml-user-select: none;
-webkit-tap-highlight-color: transparent;
margin-left: -10px;
}
.embla__slide {
position: relative;
min-width: 50%;
padding-left: 10px;
}
.embla__slide__inner {
position: relative;
overflow: hidden;
height: 190px;
}
.embla__slide__img {
position: absolute;
display: block;
top: 50%;
left: 50%;
width: auto;
min-height: 100%;
min-width: 100%;
max-width: none;
transform: translate(-50%, -50%);
}
Video: https://youtu.be/Ff2r0oNi9hc
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Carousel not working when window is resized - Stack Overflow
Your problem stems from not rechecking the width of the browser more than once. It checks on page load and then sets your...
Read more >Why does my Carousel not function properly when ... - Reddit
Remount the image or carousel after the resize using a key prop. The browser is preserving the image size after it loads the...
Read more >IOS 15 touch drag is not working properly · Issue #1177 - GitHub
But yes, there's the resize issue where if you start to scroll down the page while the carousel is still animating then safari...
Read more >Lazy Loading Images – The Complete Guide - ImageKit.io
The resize and orientationChange events are equally important for lazy loading. The resize event occurs when the size of the browser window ......
Read more >CSS-Only Carousel - CSS-Tricks
Get started with $200 in free credit! It's kind of amazing how far HTML and CSS will take you when building a carousel/slideshow....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@davidcetinkaya all good now thanks, the reInit did help prevent the setup glitch, but after applying the opacity fade, it adds a nice effect to the page to see the carousels fade (0.3s via GSAP ) 👍
Thanks again for the info 😃
Embla is my go to carousel, I’ve never been a fan of the others, and I wont touch anything jQuery. Embla is the closes way to how I would build a carousel and expect it to be init and behave. Also a 1/4 of the css the others take.
Keep up the great work.
Thanks Darcey
@DarceyLloyd let me know how it goes. Cheers.