I am facing an issue in Slick Carousel to work in both LTR and RTL. It works by default in LTR, but when I change the page to RTL I get a blank container. There is an option “rtl: true” but that would make it always working in rtl.
I have tried to add a conditional function in JS file where it can work in both.
JavaScript
x
7
1
function rtl_slick(){
2
if ($('body').hasClass("rtl")) {
3
return true;
4
} else {
5
return false;
6
}}
7
This is the conditional function I used. But it did not work. I’m not sure what I did wrong.
JavaScript
1
11
11
1
$('.first-screen-slider').slick({
2
infinite: true,
3
slidesToShow: 1,
4
slidesToScroll: 1,
5
arrows: false,
6
dots: false,
7
autoplay: true,
8
autoplaySpeed: 2000
9
rtl: rtl_slick(), // this is where the function should work
10
});
11
This is the package website: https://kenwheeler.github.io/slick/
Advertisement
Answer
to get it to work you need 2 things:
- add the attribute dir=”rtl” to the parent
JavaScript
1
4
1
<div id="slider" dir="rtl">
2
///your slides///
3
</div>
4
- add the option {rtl:true} to the options