jquery draggable: how to limit the draggable area?

后端 未结 5 2094
独厮守ぢ
独厮守ぢ 2020-12-01 04:58

I have a draggable object (div), and some droppable ones (table TD\'s). I want the user to drag my draggable object to one of those droppable TD\'s.

I enable draggab

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 05:48

    Here is a code example to follow. #thumbnail is a DIV parent of the #handle DIV

    buildDraggable = function() {
        $( "#handle" ).draggable({
        containment: '#thumbnail',
        drag: function(event) {
            var top = $(this).position().top;
            var left = $(this).position().left;
    
            ICZoom.panImage(top, left);
        },
    });
    

提交回复
热议问题