Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to disable swiper for certain breakpoint only? #3175

Closed
oneezy opened this issue Aug 14, 2019 · 4 comments
Closed

Question: How to disable swiper for certain breakpoint only? #3175

oneezy opened this issue Aug 14, 2019 · 4 comments

Comments

@oneezy
Copy link

oneezy commented Aug 14, 2019

I only want to allow swiper to work when it's between 0 - 768px and not work in any resolution above that. Is there an easy way to achieve this?

@oneezy
Copy link
Author

oneezy commented Aug 14, 2019

I actually found out about the init() and destroy() methods and by adding init: false to the swiper variable.. but how can i continuously init and destroy? right now it only allows me to do it once. here's what i currently have (resize the window to initialize or destroy the swiper).

https://codepen.io/oneezy/pen/eYOZzWY

@EHFVF
Copy link

EHFVF commented Aug 16, 2019

Hi oneezy,
the problem is probably that the function init(); does not instantiate the swiper object with the same settings again.
A solution could be to replace the init() function call by a 'new' instantiation (on first call or after destroy() ). I quickly modified your js code accordingly, it should work (html and css unchanged), please check:
https://codepen.io/EFX/pen/xxKOwLw
Best,

@oneezy
Copy link
Author

oneezy commented Aug 19, 2019

Thanks @EHFVF ! That's a perfect solution

@oneezy oneezy closed this as completed Aug 19, 2019
@EHFVF
Copy link

EHFVF commented Aug 20, 2019

Hi oneezy,
thank you for your reply.
Please be warned that it is not a perfect solution, it is a prototype.
To get it perfect, you should prevent potential js errors, e.g. if the user starts in desktop mode, then the call "swiper.destroy();" will throw an error, because the "swiper" object has not be instantiated, yet etc.
All the best,

@lock lock bot added the outdated label Apr 17, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants