jquery ui ddraggable : limit dragable area by pixels

大城市里の小女人 提交于 2021-02-08 06:44:24

问题


I have an Image and I want to allow users to drag the image only in Y axis and I have to limit the dragging by pixels, which means users can drag only 200 pixels in Y axis (either upside and downside)

  <script>
  $(function() {
    $( "#img" ).draggable({ axis: "y" });
  });
  </script>

I could limit the dragging in Y axis only but I didn't see an option to limit the dragging in pixels.

please help


回答1:


There is also the option 'containment' where you can specify a bounding box with coordinates (among other options).

$( "#img" ).draggable({ containment: [x1, y1, x2, y2] });

http://api.jqueryui.com/draggable/#option-containment

Here is a JSFiddle where I limit the movement of the image between 0-200 pixels on the y axis. http://jsfiddle.net/m3e6V/



来源:https://stackoverflow.com/questions/19962266/jquery-ui-ddraggable-limit-dragable-area-by-pixels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!