问题
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