我是一个完整的 jQuery 和 Javascript 菜鸟,试图让一个非常简单的拖放现场演示工作。我越来越近了,但我拖动的元素被赋予了绝对定位,所以它们不能很好地融合在一起。
标记非常简单:
<section class="favrecentboxessection" id="favorites">
little divs with the style set to draggable
</section>
<section class="favrecentboxessection" id="recents">
where they are dragged to
</section>
还有我伤心的小 jQuery:
$( init );
var $favorites = $( "#favorites" ),
$recent = $( "#recent" );
function init() {
$('.favrecentbox').draggable( {
cursor: 'move',
containment: '#mainsection',
stack: '.favrecentbox',
revert: 'invalid',
revertDuration: 200,
} );
$('.favrecentboxessection').droppable( {
accept: ".favrecentbox",
activeClass: 'ui-state-highlight',
drop: function (event, ui) {
handleDropEvent (ui.draggable);
}
} );
function handleDropEvent( $item ) {
var temp;
temp = $item.detach();
temp.appendTo( $('#favorites'));
我已经进行了拖动工作,但是当它们放下时,它们会保留绝对定位(设置了左侧、顶部等)。我该如何关闭它?