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

javascript - Slick slider - Change draggable state on input focus event - Stack Overflow

programmeradmin5浏览0评论

I'm trying to remove draggable option while I'm in an input field (so I can select text and navigate inside the field with the arrows).

var slider = $('.slider').slick({
    infinite: false,
    speed: 300,
    slidesToShow: 1,
    adaptiveHeight: true,
    asNavFor: '#menu-mobile',
    draggable: true
});

$('input').focusin(function () {
    console.log('in');
    slider.slickSetOption("draggable", false, false);
}).focusout(function () {
    console.log('out');
    slider.slickSetOption("draggable", true, false);
});

It returns

Uncaught TypeError: undefined is not a function

on both events.

How do I change the draggable/swipe state with an event?

I'm trying to remove draggable option while I'm in an input field (so I can select text and navigate inside the field with the arrows).

var slider = $('.slider').slick({
    infinite: false,
    speed: 300,
    slidesToShow: 1,
    adaptiveHeight: true,
    asNavFor: '#menu-mobile',
    draggable: true
});

$('input').focusin(function () {
    console.log('in');
    slider.slickSetOption("draggable", false, false);
}).focusout(function () {
    console.log('out');
    slider.slickSetOption("draggable", true, false);
});

It returns

Uncaught TypeError: undefined is not a function

on both events.

How do I change the draggable/swipe state with an event?

Share Improve this question edited Sep 16, 2017 at 15:30 Gleb Kemarsky 10.4k7 gold badges46 silver badges71 bronze badges asked Mar 4, 2015 at 18:53 Estevan MaitoEstevan Maito 1,8082 gold badges21 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

The plugin registers only function jQuery.fn.slick.

Methods are called on slick instances through the slick method itself in version 1.4

It is needed to call it like this:

// pseudocode
slider.slick("method", arguments, ...)

To fix your code change:

// wrong
slider.slickSetOption("draggable", false, false);

to:

// correct
slider.slick("slickSetOption", "draggable", false, false);

//Arguments: option : string, value : depends on option, refresh : boolean

Working demo: https://jsfiddle.net/mattydsw/Lsj62qsx/25/

发布评论

评论列表(0)

  1. 暂无评论