jQuery拖动重置位置,双击

时间:2011-09-01 14:39:34

标签: jquery css html5 html4

我对此jsfiddle example感到有些困惑。当用户拖动方块时,一切正常。但是当用户在将其拖离原始位置后双击方块时,我希望它返回原始位置,该位置仅半工作(垂直)。它不是正确的! 任何帮助非常感谢:)

1 个答案:

答案 0 :(得分:0)

你能做到(我纠正了你的小提琴,因为它完全错了):

jQuery("#drag_item").draggable({containment: '#container'});
var position = jQuery("#drag_item").position();
//you could also use 
//var position = jQuery("#drag_item").offset();

$("#drag_item").dblclick(function() {



    $('#drag_item').css({
        'top': position.top
    });

    $('#drag_item').css({
        'position': 'fixed'
    });
    $('#drag_item').css({
        'left': position.left
    });
});

在这里摆弄http://jsfiddle.net/6kXTP/5/