jQuery draggable revert based on condition

前端 未结 2 1695
日久生厌
日久生厌 2020-12-16 23:36

I am having an issue related jQuery draggable and droppable. Here is description something what I want to do.

First: I have two divs. One is &

2条回答
  •  -上瘾入骨i
    2020-12-16 23:47

    You can use the accept option which takes a function to do this much easier, like this:

    $("#selected ul").droppable({
        accept: function() {
            return $("#selected li").length < 5;
        }
    });
    

    You can test it out here. When you drag elements out, the .length goes down and it'll accept elements again...no reason to get any more complicated :)

提交回复
热议问题