javascript 光滑滑块 - 在输入焦点事件上更改可拖动状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28862528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Slick slider - Change draggable state on input focus event
提问by Estevan Maito
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?
如何使用事件更改可拖动/滑动状态?
回答by mkutyba
The plugin registers only function jQuery.fn.slick
.
该插件仅注册 function jQuery.fn.slick
。
Methods are called on slick instances through the slick method itself in version 1.4
在 1.4 版中通过 slick 方法本身在 slick 实例上调用方法
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/