使用 jQuery Draggable 在 div 剪贴蒙版中拖动缩放图像?
我正在创建一个界面,允许用户放大图像并在剪切蒙版 div 内拖动缩放版本。
我有一个 div 200px x 200px
,我将其设置为 Overflow:hidden。然后我将一个 std img () 加载到 div 中,即
1000px x 1000px
。
然后我使用 jQuery 对
$("#my-image").draggable({ containment: [-85,83,99,222] });
数字进行硬编码。到目前为止,我只能通过反复试验找到它们...
问题是,每次我对页面进行更改(即在容器 div 上方插入另一个元素)时,页面大小都会发生变化,并且我的硬编码 [x1, y1, x2, y2] 停止正常工作。
主要问题是我不完全理解 [x1, y1, x2, y2] ...
这是关于此的 jQuery 文档:
http://docs.jquery.com/UI/Draggable#option-containment
我是否正确地认为 x1 是最左边的可拖动点,x2 是最右边的可拖动点观点? (y1 和 y2 也一样)?
如果是这样,动态计算它们的最佳策略是什么?
此外,对于“在 div 剪贴蒙版内拖动缩放图像”这一主要问题的任何其他快速且简单的解决方案将不胜感激。
I'm creating an interface to allow a user to zoom in on an image and drag the zoomed version around within a clipping mask div.
I have a div 200px by 200px
that I set overflow: hidden on. Then I load a std img (<img src="etc">
) into the div that is, say, 1000px by 1000px
.
Then I use jQuery
$("#my-image").draggable({ containment: [-85,83,99,222] });
The numbers are hard coded. So far I can only find them by trial and error...
The problem is that each time I make a change to the page (Ie insert another element above my container div) the page size changes and my hard coded [x1, y1, x2, y2] stop working correctly.
The main issue is I don't fully understand [x1, y1, x2, y2] ...
Here is the jQuery docs regarding this:
http://docs.jquery.com/UI/Draggable#option-containment
Am I right in thinking that x1 is the left most draggable point, x2 is the right most draggable point? (and same for y1 & y2)?
If so, what would be the best strategy to calculate them dynamically?
Also, any other quick and easy solutions to the main problem of "Drag a zoomed image within a div clipping mask" would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的。我现在已经开始工作了。这是如何在 div 剪贴蒙版中设置可拖动图像,以便它完全动态并且无论您如何调整页面大小都可以工作。
HTML/CSS
jQuery/JavaScript
希望这对某人有帮助!
Ok. I've got this working now. This is how to set up a draggable image within a div clipping mask so that it is completely dynamic and works no matter how you resize the page.
The HTML/CSS
The jQuery/JavaScript
Hope this helps someone!