-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 hide arrows if I have only one item in slider #1403
Comments
I have this issue too and also come across a slightly wider issue where what happens if you have two items in the list, so on desktop there is no slide function as there is nothing to slide to - the buttons need to disappear but they dont. Also, then when you move the browser size down to mobile portrait view where only 1 list item is visible at a time, the buttons should now show. Im guessing there needs to be some sort of logic here where the buttons are hidden list items are equal to or less than the number of slides visible |
Hey please make a fiddle/pen when asking for help. I've never seen the arrows apply when there's only one slide. Here's a codepen illustrating them not showing when there's one slide. |
Ah I see. Yeah, so I guess in a perfect world the library would hide the selector-defined arrows if there's only one slide, but because they're existing elements in the markup I can see how an argument can be made for leaving them. Luckily the fix is pretty easy; just test for slide length on init, and if it's 1 then hide the arrows. |
Ok, it works, thx. |
would be fixed by #1331 :) |
@leggomuhgreggo how do i test it? |
@HiimF You need to place the init event code before you intialize the slider, and then create an if statement that will count the amount of slides on load, and then hide the arrows if necessary. The following code should work for you, or at least point you in the right direction:
|
Just figured this out! Add anywhere after you call swiper js if using looped slides:
or if not using looped slides:
.swiper-button-prev and .swiper-button-next would be the class names of the arrows |
It might also be wise to only init the slider if there is more than 1 slide:
|
@iamkeir Isn't .slick-slide added during init though, so the above condition fails always? |
@andypimlett sounds likely - best to count the pre-Slicked elements instead. |
Came across this when trying to see how others did this. This solution should work better though:
|
See this issue: #1403 -- dots are hidden automatically when only one slide if you use slick.js and not slick.min.js. |
Just had this issue, switched to .min.js for production and dots appered on single item slides. Why is it different code in the minified version? Very confusing. Creating your own minified version solves the problem, obviously... |
Please fix this.... |
@amoralesdesign the above comment fixes it - count children, if larger than 1, init slider: It would be nice if it was handled natively but Slick does not seem to be actively developed - although if you create a PR, the owners do seem to be merging them. |
How can I hide arrows if my slide show consists of only one item?
The text was updated successfully, but these errors were encountered: