最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I'm trying to enabledisable Slick Slider between a set window width (responsive) - Stack Overflow

programmeradmin2浏览0评论

I'm trying to enable Slick Slider (slick.js) to initiate only over 520px wide. Anything below that and the slides just stack (i.e. no slick). Is it possible so that it can work without refreshing the page?

I've done this, but it's really clunky:

$(document).ready(function () {

    var $window = $(window),
        $slick = $('.slick'),
        toggleSlick;

    toggleSlick = function () {
        if ($window.width() > 520) {
            $slick.slick();
        } else {
            $slick.unslick();
        }
    }

    $window.resize(toggleSlick);
    toggleSlick();
});

I also get a Uncaught TypeError: $slick.unslick is not a function error in the console.

I'm using

I'm trying to enable Slick Slider (slick.js) to initiate only over 520px wide. Anything below that and the slides just stack (i.e. no slick). Is it possible so that it can work without refreshing the page?

I've done this, but it's really clunky:

$(document).ready(function () {

    var $window = $(window),
        $slick = $('.slick'),
        toggleSlick;

    toggleSlick = function () {
        if ($window.width() > 520) {
            $slick.slick();
        } else {
            $slick.unslick();
        }
    }

    $window.resize(toggleSlick);
    toggleSlick();
});

I also get a Uncaught TypeError: $slick.unslick is not a function error in the console.

I'm using https://github./kenwheeler/slick

Share Improve this question asked Aug 17, 2015 at 14:36 Jack BarhamJack Barham 3,21912 gold badges45 silver badges64 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

I believe the way you call slick methods has changed.

Instead of $('.slick').unslick();

try $('.slick').slick("unslick");

You can also call this directly inside the responsive option in the slick options

发布评论

评论列表(0)

  1. 暂无评论