2013-08-03 83 views
0

將jQuery UI可拖動元素固定到軸很簡單。您只需設置軸選項,但仍然允許兩個方向的拖動。使jQuery UI可拖動元素只能在向下方向拖動

如何限制只拖動到一個方向(向下)?

$('.settings').draggable({axis:'y'});使得.settings可以上下拖動,但是我怎樣才能讓它只能向下運行?

+0

這裏有一個UP唯一無二:http://stackoverflow.com/questions/16619895/restricting-jquery-ui-draggable-to-drag-up-only-within-a-given-area – DevlshOne

+0

@ DevlshOne該代碼沒有意義。他的可拖動的執行沒有做任何阻止向下拖動,但它阻止向下拖動? –

+0

你在看問題還是接受的答案?他的代碼其實很精彩。它檢查拖拽是否離DOM頂端越來越遠,然後拒絕該移動。你只需要實現相同的東西,但相對於DOM的「底部」。 – DevlshOne

回答

1
$('#repel').mousemove(function() { 
    var z = $(window).scrollTop(); 
    var o = $('#repel').offset().top; 
    var h = $('#repel').height(); 
     $("#containment-wrapper").css({ 
      top: o + h -2000 
     }); 
    if (z < 10) { 
     $("#containment-wrapper").css({ 
      top: -850 
     }); 
    } else { 
     $("#containment-wrapper").css({ 
      top: o + h -2000 
     }); 
    } 
});