Jquery可拖动约束使用拖动功能 [英] Jquery draggable constrain using drag function

查看:104
本文介绍了Jquery可拖动约束使用拖动功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在非常复杂的几何形状中使用jQuery draggable,并且无法预先计算帧。

I need to use jQuery draggable in quite a complicated geometrical shape, and it is not possible to calculate the frame beforehand.

因此,包含选项不会被切断解决这个问题。

So, containment option isn't cut for solving this problem.

我一直在考虑拖动功能,检查我的状况并返回false以防止拖动。
但是,问题是,在第一次从拖拽功能返回false后,拖动过程停止,就好像用户已经释放鼠标按钮一样。

I've been thinking about drag function, checking my condition and returning false to prevent dragging. But, the problem is, that after returning false from drag function for the first time, dragging process stops, as if user have released the mouse button.

有关防止在不取消拖动过程的情况下拖出形状的建议吗?

Any suggestions on preventing dragging out of the shape without canceling dragging process?

推荐答案

我已解决了与resizable类似的问题。我不得不手动设置大小。
尝试类似的事情:

I have solved similar issue with resizable. I had to manually set sizes though. Try something like that:

yourdraggable.bind( 'drag', function() {

  var left = $(this).css('left'),
      top = $(this).css('top'),
      width = $(this).width(), 
      height= $(this).height();

  //determine if dragging should contain or continue

  //if contain 
  $(this).css( { left: containLeft, top: containTop } );

});

你可以单独分析左边和顶部,但你明白了

You could analyze left and top separately but you got the idea

这篇关于Jquery可拖动约束使用拖动功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆