jquery draggable has an issue on dragging?

后端 未结 1 388
深忆病人
深忆病人 2020-12-22 10:49

I wanted to restore the position of red block which is a draggable div on the green and gray block and not in blue block it is not worked on green block but it worked on gra

相关标签:
1条回答
  • 2020-12-22 11:31

    I have not used draggable jquery but would

    $("#nodrag").droppable({drop: function() { $('#draggable').css({top:'0px',left:'0px'});}});
    

    work?

    Looking further into the draggable stuff there isn't an obvious way to the revert with blocks inside valid elements so I would do the folllowing

    $("#draggable").draggable('option', 'start', function(){
       //when drag starts save the positions somewhere
       $(this).data('left',$(this).css('left')).data('top',$(this).css('top'))
    });
    $("#nodrag").droppable({drop: function(e,ui) {
        //when dropped on an invalid block move it back to where it was (you could change this to animate to mimic revert)
        $(ui.draggable)
       .css({left:$(ui.draggable).data('left'),top:$(ui.draggable).data('top')});
    }});
    
    0 讨论(0)
提交回复
热议问题