我需要在Slick-slider中有一个jQuery UI可拖动元素。我知道jQuery UI有句柄选项http://jqueryui.com/draggable/#handle,但我不知道如何将其应用于光滑滑块。
我发现了这个问题:jQuery UI Slider Interference with slick carousel但它使用的是jQuery UI' slider
选项。当我在我的例子中做了类似的事情时,我能够禁用光滑滑块拖动...但是我的可拖动元素仍然无法拖动。
JSfiddle:http://jsfiddle.net/NateW/u1burczm/
当我的某个 HTML: JS:draggable
元素内部仍然有draggable
元素可拖动时,如何禁用仅在滑块 上拖动?< / p>
<div class="wrapper-slider">
<div>
<div id="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>
<div id="draggable" class="ui-widget-content">
<p>and me!</p>
</div>
</div>
<div><h3>1</h3><h3>1</h3><h3>1</h3></div>
<div><h3>2</h3><h3>2</h3><h3>2</h3><h3>2</h3></div>
<div><h3>3</h3><h3>3</h3></div>
</div>
$('.wrapper-slider').slick({
dots: false,
infinite: false,
centerPadding: "20px",
speed: 300,
slidesToShow: 1,
adaptiveHeight: true
});
$(function() {
$( ".draggable-element" ).draggable();
});
$(".draggable-element").on("draggable mouseenter mousedown",function(event){
event.stopPropagation();
});
答案 0 :(得分:14)
要使其正常工作,您需要在将draggble绑定到元素之前取消绑定由光滑滑块注册的dragstart事件,如下所示
$('.wrapper-slider').slick({
dots: false,
infinite: false,
centerPadding: "20px",
speed: 300,
slidesToShow: 1,
adaptiveHeight: true
});
$(function() {
$('*[draggable!=true]','.slick-track').unbind('dragstart');
$( ".draggable-element" ).draggable();
});
$(".draggable-element").on("draggable mouseenter mousedown",function(event){
event.stopPropagation();
});
这是工作jsfiddle http://jsfiddle.net/samcoolone70/u1burczm/3/