jQuery UI:可拖动元素的包含有问题

发布于 2024-08-22 17:42:21 字数 2039 浏览 5 评论 0原文

我正在开发的一个网站有图像缩放功能,并且缩放后的图像是可拖动的。

问题是,在当前版本中,您可以放大图像,然后将图像完全拖出可视区域。

请参阅:http://testing.successfulsites.co.uk/s5/1.3。 5.1.html(并放大)

(很抱歉 URL 中存在空白 - 我是新用户,因此无法发布超过 1 个链接!)

因此,我一直在尝试将图像获取到被遏制。

我采取的方法是对我正在创建的 div 进行包含,并根据当前的缩放级别调整其大小。

div 包裹在缩放容器 div 周围,并具有负边距和正填充,以便正确定位自身。

请参阅:http://testing.successfulsites.co.uk/s6/1.3。 5.1.html(并放大)

注意:在问题得到解决之前,我没有考虑过“缩小”的遏制功能。

我添加了 CSS,以便您可以看到涉及的各种 div。

我遇到的问题是,当您放大并拖动图像时,它会被包含 - 但只有当您将手指从鼠标按钮上移开时..然后包含区域似乎会重置甚至跳跃 - 这意味着您可以移动图像仍然离开观看区域 - 只是不是一次性的。

JS 文件位于:

http://testing.successfulsites.co。 uk/s6/assets/js/functions.js

CSS 在这里:

http://testing.successfulsites.co.uk/s6/assets/style/main.css

这是相关代码:

在以下函数中...

$("#in").live("click",function () {

我有以下代码...

if(currentZoom > 1) {
 if ($('#zoom-meta-container').length == 0) {
  $('#zoom-container').wrap('<div id="zoom-meta-container"></div>');
  var container = $('#zoom-meta-container');
  $('#zoom-container a').draggable({ containment: container });
  $('#zoom-container').addClass('drag-cursor');
 };
 switch (currentZoom) {
  case 1:  
  container.css('margin','-20% 0 0 -20%').css('padding','20%');
  break;

  case 2:  
  container.css('margin','-90% 0 0 -90%').css('padding','90%');
  break;

  case 3:  
  container.css('margin','-160% 0 0 -160%').css('padding','160%');
  break;

  case 4:  
  container.css('margin','-210% 0 0 -210%').css('padding','210%');
  break;
 };

任何想法..

1)我做错了什么?

2)对于原来的问题是否有更好的方法?

A site I'm working on has an image zoom, and the zoomed image is draggable.

The problem is that on the current version you can zoom in and then drag the image totally out of the viewable area.

See: http://testing.successfulsites.co.uk/s5/1.3.5.1.html (and zoom in)

(sorry about the gap in the URL - I'm a new user so can't post more than 1 link!)

So, I've been trying to get the image to be contained.

The approach I've taken is to use containment on a div which I'm creating and resizing, based on the current zoom level.

The div is wrapped around the zoom-container div, and has negative margins and positive padding, in order to position itself correctly.

See: http://testing.successfulsites.co.uk/s6/1.3.5.1.html (and zoom in)

Note: I haven't bothered with the containment functionality on "zoom out" - until the issue is fixed.

I've added CSS in so that you can see the various divs involved.

The issue I'm having is that when you zoom in and drag the image it's contained - but ONLY until you let your finger off the mouse button .. and then the containment area seems to reset and even jump - meaning you can move the image off the viewing area still - just not in one go.

The JS file is here:

http://testing.successfulsites.co.uk/s6/assets/js/functions.js

The CSS is here:

http://testing.successfulsites.co.uk/s6/assets/style/main.css

Here's the relevant code:

In the following function...

$("#in").live("click",function () {

I have the following code...

if(currentZoom > 1) {
 if ($('#zoom-meta-container').length == 0) {
  $('#zoom-container').wrap('<div id="zoom-meta-container"></div>');
  var container = $('#zoom-meta-container');
  $('#zoom-container a').draggable({ containment: container });
  $('#zoom-container').addClass('drag-cursor');
 };
 switch (currentZoom) {
  case 1:  
  container.css('margin','-20% 0 0 -20%').css('padding','20%');
  break;

  case 2:  
  container.css('margin','-90% 0 0 -90%').css('padding','90%');
  break;

  case 3:  
  container.css('margin','-160% 0 0 -160%').css('padding','160%');
  break;

  case 4:  
  container.css('margin','-210% 0 0 -210%').css('padding','210%');
  break;
 };

Any ideas..

1) What I'm doing wrong?

2) If there's a better approach to the original problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白龙吟 2024-08-29 17:42:21

这可能超出了遏制选项的设计范围。我会尝试通过在拖动回调中使用 return false 来进行自定义遏制。

This may be beyond the design of the containment option. I would try doing custom containment by using return false in a drag callback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文