开发者

How control dragging only a side, such left side only by jqueryui drag?

开发者 https://www.devze.com 2023-02-18 13:36 出处:网络
$(\".draggable\").draggable({axis: \'x\'}); <div 开发者_如何学Cclass=\"draggable\"> I am draggable to left side only, and not right or up or down, the axis : x controls me to prevent up or do
$(".draggable").draggable({axis: 'x'});

<div 开发者_如何学Cclass="draggable">

I am draggable to left side only, and not right or up or down, the axis : x controls me to prevent up or down dragging, but make me not right too. Thanks


I solved it saving the previous left offset and comparing it with the new left offset.

var previousOffset = null;

$( "#draggable" ).draggable({
  axis: 'x',
  drag: function(event,ui){
    if(previousOffset == null)
       previousOffset = ui.offset.left;
    else{
      if(previousOffset < ui.offset.left)
        return false; 
      else
        previousOffset = ui.offset.left;
    }
  }
});

Here's working: http://jsbin.com/ubine3/2

0

精彩评论

暂无评论...
验证码 换一张
取 消