<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<!DOCTYPE html><html lang='en' class=''>
<head><script src='//production-assets.codepen.io/assets/editor/live/console_runner-079c09a0e3b9ff743e39ee2d5637b9216b3545af0de366d4b9aad9dc87e26bfd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/events_runner-73716630c22bbc8cff4bd0f07b135f00a0bdc5d14629260c3ec49e5606f98fdd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/css_live_reload_init-2c0dc5167d60a5af3ee189d570b1835129687ea2a61bee3513dee3a50c115a77.js'></script><meta charset='UTF-8'><meta name="robots" content="noindex"><link rel="shortcut icon" type="image/x-icon" href="//production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" /><link rel="mask-icon" type="" href="//production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" /><link rel="canonical" href="https://codepen.io/danielsintrao/pen/OgWJae?limit=all&page=64&q=draggable" />
<style class="cp-pen-styles">* {
margin: 0;
padding: 0;
}
body {
background-color: #2c3e50;
}
.drag-list {
display: flex;
flex-direction:column;
width: 300px;
margin: 150px auto;
}
.dragOver {
border-top: 20px solid rgb(255, 255, 229) !important;
border-bottom: 20px solid rgb(255, 255, 229) !important;
background-color: rgba(0,0,0,.05);
}
.drag-item {
font-family: Helvetica;
height: 30px;
margin: 10px 10px 0 10px;
padding: 10px;
transition: box-shadow .1s ease-in-out;
text-align: center;
border: 1px solid rgba(0,0,0,.03);
border-radius: 3px;
background-color: #ecf0f1;
}
.slide-placeholder {
position: relative;
}
.ui-sortable-helper {
box-shadow: 0 3px 10px rgba(0,0,0,.1), 0 10px 30px rgba(0,0,0,.05);
}
</style></head><body>
<div class="drag-list">
<div class="drag-item">Item 1</div>
<div class="drag-item">Item 2</div>
<div class="drag-item">Item 3</div>
<div class="drag-item">Item 4</div>
<div class="drag-item">Item 5</div>
</div>
<script src='//production-assets.codepen.io/assets/common/stopExecutionOnTimeout-b2a7b3fe212eaa732349046d8416e00a9dec26eb7fd347590fbced3ab38af52e.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js'></script>
<script >$(".drag-list").sortable({
axis: 'y',
placeholder: 'slide-placeholder',
revert: 150,
start: function (e, ui) {
var placeholderHeight = ui.item.outerHeight();
ui.placeholder.height(placeholderHeight);
ui.placeholder.css({
'margin-top': ui.item.css('margin-top'),
'margin-right': ui.item.css('margin-right'),
'margin-bottom': ui.item.css('margin-bottom'),
'margin-left': ui.item.css('margin-left')
});
$('<div class="slide-placeholder-animator" data-height="' + placeholderHeight + '"></div>').insertAfter(ui.placeholder);
},
change: function (event, ui) {
ui.placeholder.stop().height(0).animate({
height: ui.item.outerHeight(),
marginTop: parseInt(ui.item.css('margin-top')),
marginRight: parseInt(ui.item.css('margin-right')),
marginBottom: parseInt(ui.item.css('margin-bottom')),
marginLeft: parseInt(ui.item.css('margin-left'))
}, 150);
placeholderAnimatorHeight = parseInt($(".slide-placeholder-animator").attr("data-height"));
$(".slide-placeholder-animator").stop().height(placeholderAnimatorHeight).animate({
height: 0,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0
}, 150, function () {
$(this).remove();
var placeholderHeight = ui.item.outerHeight();
$('<div class="slide-placeholder-animator" data-height="' + placeholderHeight + '"></div>').insertAfter(ui.placeholder);
});
},
stop: function (e, ui) {
console.log($(".drag-list drag-item").first().text());
$(".slide-placeholder-animator").remove();
},
});
//# sourceURL=pen.js
</script>
</body></html>