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();
});
Check whether your draggable object is already loaded in the viewport. If it is not, it won't work properly. JUST AFTER the draggable object to be absolutely sure that everything is loaded at the correct time. When you'll be sure everything is ok, then you'll be able to refactor.
Draggable() Method This method allows the elements to be dragged with the help of mouse. Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port.
slick('slickSetOption', 'autoplay', false, false); });
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With