Skip to content

Instantly share code, notes, and snippets.

@risingsunomi
Created March 14, 2015 20:04
Show Gist options
  • Save risingsunomi/f553de04c96698d00ed4 to your computer and use it in GitHub Desktop.
Save risingsunomi/f553de04c96698d00ed4 to your computer and use it in GitHub Desktop.
Drag and Drop Owl Carousel
$.fn.outerHTML = function(s) {
return s
? this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();
};
$(function(){
$(".owl-carousel").owlCarousel({
mouseDrag: false,
touchDrag: false,
});
$('#owl > .owl-wrapper-outer > .owl-wrapper > .owl-item > .my-owl-item').droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function( event, ui ) {
var drhtml = $(ui.draggable).html();
var thtml = $(this).html();
$(ui.draggable).html(thtml);
$(this).html(drhtml);
}
});
$('#owl > .owl-wrapper-outer > .owl-wrapper > .owl-item > .my-owl-item' ).draggable({
start: function( event, ui ) {console.log('dragging');},
stop: function(event, ui) { console.log(event,ui); },
helper : 'clone',
containment: '#owl > .owl-wrapper-outer > .owl-wrapper'
});
});
<div id="owl" class="owl-carousel">
<div class="my-owl-item">
<img src="http://lorempixel.com/200/150/abstract" alt="" />
</div>
<div class="my-owl-item">
<img src="http://lorempixel.com/200/150/business" alt="" />
</div>
<div class="my-owl-item">
<img src="http://lorempixel.com/200/150/cats" alt="" />
</div>
<div class="my-owl-item">
<img src="http://lorempixel.com/200/150/city" alt="" />
</div>
<div class="my-owl-item">
<img src="http://lorempixel.com/200/150/people" alt="" />
</div>
</div>
.ui-state-hover { border: 1px solid red; }
#owl > .owl-wrapper-outer > .owl-wrapper > .owl-item > .my-owl-item > img { width: 100%; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment