Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
179
rated 0 times [  183] [ 4]  / answers: 1 / hits: 16695  / 9 Years ago, wed, april 8, 2015, 12:00:00

I need to have a jQuery UI draggable element inside a Slick-slider. I know that jQuery UI has the handles option http://jqueryui.com/draggable/#handle but I'm not sure how to apply this to the slick-slider.



I found this SO question: jQuery UI Slider Interference with slick carousel but it's using jQuery UI's slider option. When I did something similar on my example I was able to disable the slick-slider dragging... But my draggable elements still aren't draggable.



JSfiddle: http://jsfiddle.net/NateW/u1burczm/



How do I disable dragging on the Slick-slider only when it's inside one of my draggable elements and still have the draggable elements draggable?






HTML:



<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>


JS:



$('.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();
});

More From » jquery

 Answers
14

for that to work you need to unbind the dragstart event registered by slick slider like follow before binding the draggble to element



$('.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();
});


here is working jsfiddle
http://jsfiddle.net/samcoolone70/u1burczm/3/


[#67145] Tuesday, April 7, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kiarra

Total Points: 202
Total Questions: 111
Total Answers: 109

Location: Sudan
Member since Mon, May 31, 2021
3 Years ago
;