Slick slider code only works for Android - why isn't it working for iOS (portrait only)?

Viewed 448

I have an issue here and would love your input. So, I have a page with 3 images side by side in desktop mode and landscape mode, and they need to turn into a slider on mobile, portrait. I used slick slider, the code below, added the newest jQuery link and worked just fine - they were all added in the same file, to test them: html, jquery cdn, jquery code. However, we are using a CMS, so when I moved the js code to a .js file and the jquery v3.5.1 loaded externally, it stopped working for iOS. Did you encounter a similar situation? Any ideas? Thanks!

    $slickTest = false;
    function startSlider() {    
        if ($(window).width() <= 540) {
            if (!$slickTest) {
                $(".responsive").slick({
                    dots: true,
                    arrows: false,
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    infinite: true
                });
                $slickTest = true;
            }
        } else if ($(window).width() > 540) {
            if ($slickTest) {
                $('.responsive').slick('unslick');
                $slickTest = false;
            }
        }
    }

    $(document).ready(function() {
        startSlider();
    });
    $(window).on('resize', function() {
         startSlider();
    });
  });
1 Answers

I managed to make it work by adding the jquery cdn in the head as opposed to how we normally add the js files as related. Adding it before the closing head tag was the solution in this case. Now it works perfectly! Thank you all :)

Related