Enable or disable on certain screen sizes
See original GitHub issueI’m trying to use Embla (which is fantastic btw, great job) only on mobile, so sort of disabling it on desktop when it’s been enabled on mobile (i.e. window resize or orientation change).
So for instance:
- Load: Desktop screen size (>768) => No carousel
- Resize: to Mobile (<768) => Init carousel
- Resize: to Desktop (>768) => Destroy carousel
- etc…
Flickity has this cool feature where it tracks if a CSS after
element has a certain content, then enables or disables it with CSS breakpoints. But it’s also 51kb of JS, so Embla is def more optimized and lightweight!
Is there any way to have a similar kind of behavior with Embla without having to listen to a window resize event and embla.destroy()
(which doesn’t seem to completely destroy my instances btw) + embla.reInit(options)
everytime? Or am I missing something?
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
How to Use the Screen Size Control - Block Visibility
The Screen Size control in Block Visibility allows you to conditionally show or hide blocks based on the width of the current screen....
Read more >Declare restricted screen support - Android Developers
Declare a maximum screen size However, if you're still not satisfied with the way Android resizes your app for large screens, you can...
Read more >Disable Javascript effect based on the screen's size
My source code is here for you to try it, make sure you reduice the size of the screen for the responsive to...
Read more >missing enable/disable by screen size for dashicons.min.css
missing enable/disable by screen size for dashicons.min.css ... What I am trying to do is to disable it on all mobile pages except...
Read more >How do I disable the scrollTrigger animation on a certain ...
Hello. On low screen resolutions I will have a completely different header, so I don't need the scrollTrigger animation. I understand that I ......
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
Hello Félix (@flayks),
Release 4.0.2 comes with a fix for this issue. Please let me know if it’s working as intended.
Best, David
Hello Félix (@flayks),
Thank you for your question. I think the code in this old issue you mention is probably outdated. A lot has changed with the React implementation of Embla Carousel since then.
I took some time to create a CodeSandbox that implements what you want to achieve. Here’s the CodeSandbox with its related code if you want to check it out:
So here’s what’s happening:
null
, and if there’s an activated instance of Embla it will destroy it automatically.null
when the screen width is >= 768.Note
Let me know if it helps! David