我是一个完整的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'));我已经让拖拽起作用了,但是当拖拽的时候,他们会进行绝对定位(左,上,等等都是设置好的)。我怎么才能把它关掉?
发布于 2011-10-26 04:36:39
您可以在删除时将其作为子级添加到droppable容器中。
$('.favrecentboxessection').droppable( {
accept: ".favrecentbox",
drop: function(ev, ui) {
$(this).append($(ui.draggable));
$(ui.draggable).css({position:'relative'});
},
activeClass: 'ui-state-highlight',
drop: function (event, ui) {
handleDropEvent (ui.draggable);
}
} );发布于 2011-10-26 04:20:01
您可以尝试使用$(x).css()在删除后操作CSS .....
发布于 2011-10-26 04:51:40
没有必要让它变得比现在更复杂。移除CSS似乎不是一个好主意。
请参阅:http://jsfiddle.net/MPy9n/6/
draggableOptions = { appendTo: "body", zIndex: 99};
$( ".favrecentbox" ).draggable(draggableOptions);
$( ".favrecentboxessection" ).droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
console.log(ui);
$( ui.draggable ).remove();
$( '<div class="favrecentbox"></div>' ).html( ui.draggable.html() ).draggable(draggableOptions).appendTo( this );
}});https://stackoverflow.com/questions/7895220
复制相似问题