jquery draggable - containment

后端 未结 4 1121
温柔的废话
温柔的废话 2020-12-30 17:11

I have a little project I\'m working on, and have an interesting containment issue using jquery\'s draggable:

Basically, I have two divs - a top & a

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 17:37

    The containment option allows an array where to set the positions where to contain it. Try this:

    var containmentTop = $("#stop-top").position().top;
    var containmentBottom = $("#stop-bottom").position().top;
    
    $('#bar').draggable({axis: 'y', containment : [0,containmentTop,0,containmentBottom] });
    

    JSFiddle example

提交回复
热议问题