jQuery UI 可拖动约束
我想做的是在一个较小的 div 中包含一个大图像,用户可以在包含的 div 中拖动它(足够简单)...类似于 http://oneblackbear.com/draggable/index.html 但我想防止用户将其拖动到容器边界之外。通过上面的示例,用户可以将图像完全拖到包含的 div 之外...我想阻止用户将图像拖到父 div 之外。
我尝试过使用 jQuery UI 可拖动,但问题是,如果我在拖动图像时使用约束选项,它会锁定到右下角,并且不再可拖动,因为子元素大于父约束。我不确定 ui 可拖动约束是否仅适用于比父容器更小的对象。
有谁有什么想法怎么办?最好使用 jQuery Draggable?
what I am trying to do is have an large image contained within a smaller div that the user can drag around within the containing div (easy enough)... similar to http://oneblackbear.com/draggable/index.html but I want to prevent users from dragging it any further then the container boundary. With the above example the user can drag the image completely outside of the containing div... I want to prevent the user from ever dragging the image outside of the parent div at all.
I have tried using jQuery UI draggable but the problem is if I use the constraint option as soon as you drag the image it locks to the bottom right and is no longer draggable because the child element is larger then the parent constraint. I am not sure if the ui draggable constraint is only intended for smaller objects then the parent container.
Does anyone have any ideas how do do with? preferably with jQuery Draggable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是对我有用的解决方案,尽管我在 Chrome 中滚动页面时仍然遇到问题:
This is the solution that worked for me, although I'm still having issues in Chrome when the page is scrolled: