JQuery-UI draggable reset to original position

后端 未结 6 1914
自闭症患者
自闭症患者 2020-12-18 22:28

This is probably very easy to do, but I always think too complicated.

I\'ve just set up a simple test with #draggable / #droppable with a fixed width/height + float:

6条回答
  •  情话喂你
    2020-12-18 23:03

    Draggable items don't keep track of their original position that I know of; only during drag and to be snapped back. You can just do this on your own, though:

    $("#draggable").data({
        'originalLeft': $("#draggable").css('left'),
        'origionalTop': $("#draggable").css('top')
    });
    
    $(".reset").click(function() {
        $("#draggable").css({
            'left': $("#draggable").data('originalLeft'),
            'top': $("#draggable").data('origionalTop')
        });
    });
    

    http://jsfiddle.net/ExplosionPIlls/wSLJC/

提交回复
热议问题