Jcrop 中的一个错误,minSize +纵横比

发布于 2024-11-17 21:09:50 字数 1356 浏览 1 评论 0原文

我正在尝试在我的应用程序中使用 Jcrop,尽管我遇到了一个错误。我去了演示页面,那里也存在这个错误。以下是创建方法。

转到此演示页面 http://deepliquid.com/projects/Jcrop/demos.php?demo=advanced

确保选中以下选项 “可以移动选择”
“可调整大小的选择” 「纵横比」 “minSize/maxSize 设置”

创建一个选定区域,将其拖动到左上角,抓住选区的右下角(就像要调整其大小一样)并将其拖动到图像的左上角。

一旦您经过图像的左上角,选择区域就会向下折叠为 0x0 像素选择。

此错误仅在设置宽高比时发生。否则它工作正常。

我想知道是否有人有使用此插件的经验来修复此错误。我已经经历了一整天了,但还没有弄清楚。

- 编辑 - 在花了几个小时之后,我基本上修复了这个错误。我更改了以下代码。

        // Magic %-)
        if(xx >= x1) { // right side <-- Changed > to >=
          if(xx - x1 < min_x) {
            xx = x1 + min_x;
          } else if (xx - x1 > max_x) {
            xx = x1 + max_x;
          }
          if(yy > y1) {
            yy = y1 + (xx - x1)/aspect;
          } else {
            yy = y1 - (xx - x1)/aspect;
          }
        } else if (xx <= x1) { // left side <-- Changed < to <=
          if(x1 - xx < min_x) {
            xx = x1 - min_x
          } else if (x1 - xx > max_x) {
            xx = x1 - max_x;
          }
          if(yy > y1) {
            yy = y1 + (x1 - xx)/aspect;
          } else {
            yy = y1 - (x1 - xx)/aspect;
          }
        }

这阻止了它崩溃,但它仍然有点问题。

--编辑结束--

I am trying to use Jcrop for my application, though I have run into a bug with it. I went to the demo page, and the bug exists there too. Here is how to create it.

Go to this demo page
http://deepliquid.com/projects/Jcrop/demos.php?demo=advanced

Make sure the following options are checked
"Selection can be moved"
"Resizable selection"
"Aspect ratio"
"minSize/maxSize setting"

Create a selected area, drag it to the upper left corner, grab the lower right corner of the selection(as if you were going to resize it) and drag it to the upper left corner of the image.

Once you pass the upper left corner of the image the select area collapses down to a 0x0 pixel selection.

This bug only happens when an aspect ratio is set. Otherwise it works fine.

I'm wondering if anyone has any experience hacking around with this plugin to where they might be able to fix this bug. I've been going through it all day and haven't been able to figure it out yet.

--Edit--
After spending a few more hours with it I was able to get the bug mostly fixed. I changed the following code.

        // Magic %-)
        if(xx >= x1) { // right side <-- Changed > to >=
          if(xx - x1 < min_x) {
            xx = x1 + min_x;
          } else if (xx - x1 > max_x) {
            xx = x1 + max_x;
          }
          if(yy > y1) {
            yy = y1 + (xx - x1)/aspect;
          } else {
            yy = y1 - (xx - x1)/aspect;
          }
        } else if (xx <= x1) { // left side <-- Changed < to <=
          if(x1 - xx < min_x) {
            xx = x1 - min_x
          } else if (x1 - xx > max_x) {
            xx = x1 - max_x;
          }
          if(yy > y1) {
            yy = y1 + (x1 - xx)/aspect;
          } else {
            yy = y1 - (x1 - xx)/aspect;
          }
        }

This stopped it from collapsing, its still acts a little buggy though.

--End Edit--

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

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

发布评论

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

评论(2

空城仅有旧梦在 2024-11-24 21:09:50

更稳定的版本似乎如下:

if(xx===x1){xx=x1+min_x;}

// Magic %-)
if (xx > x1) { // right side
    if (xx - x1 < min_x) {
        xx = x1 + min_x;
    } else if (xx - x1 > max_x) {
        xx = x1 + max_x;
    }
    if (yy > y1) {
        yy = y1 + (xx - x1) / aspect;
    } else {
        yy = y1 - (xx - x1) / aspect;
    }
} else if (xx < x1) { // left side
    if (x1 - xx < min_x) {
        xx = x1 - min_x;
    } else if (x1 - xx > max_x) {
        xx = x1 - max_x;
    }
    if (yy > y1) {
        yy = y1 + (x1 - xx) / aspect;
    } else {
        yy = y1 - (x1 - xx) / aspect;
    }
}

A more stable version seems to be the following:

if(xx===x1){xx=x1+min_x;}

// Magic %-)
if (xx > x1) { // right side
    if (xx - x1 < min_x) {
        xx = x1 + min_x;
    } else if (xx - x1 > max_x) {
        xx = x1 + max_x;
    }
    if (yy > y1) {
        yy = y1 + (xx - x1) / aspect;
    } else {
        yy = y1 - (xx - x1) / aspect;
    }
} else if (xx < x1) { // left side
    if (x1 - xx < min_x) {
        xx = x1 - min_x;
    } else if (x1 - xx > max_x) {
        xx = x1 - max_x;
    }
    if (yy > y1) {
        yy = y1 + (x1 - xx) / aspect;
    } else {
        yy = y1 - (x1 - xx) / aspect;
    }
}
洛阳烟雨空心柳 2024-11-24 21:09:50

这是我的补丁,我认为它比其他发布的补丁产生更好的行为。它特别消除的一件事是在演示中使用 minSize 并在边缘附近切换边时看到的弹出到边缘的情况。

@@ -578,44 +578,36 @@
         }

         // Magic %-)
-        if (xx > x1) { // right side
+        if (xx >= x1) { // right side
           if (xx - x1 < min_x) {
             xx = x1 + min_x;
           } else if (xx - x1 > max_x) {
             xx = x1 + max_x;
           }
-          if (yy > y1) {
+          if (yy >= y1) {
             yy = y1 + (xx - x1) / aspect;
           } else {
             yy = y1 - (xx - x1) / aspect;
           }
-        } else if (xx < x1) { // left side
+        } else { // left side
           if (x1 - xx < min_x) {
             xx = x1 - min_x;
           } else if (x1 - xx > max_x) {
             xx = x1 - max_x;
           }
-          if (yy > y1) {
+          if (yy >= y1) {
             yy = y1 + (x1 - xx) / aspect;
           } else {
             yy = y1 - (x1 - xx) / aspect;
           }
         }

-        if (xx < 0) {
-          x1 -= xx;
-          xx = 0;
-        } else if (xx > boundx) {
-          x1 -= xx - boundx;
-          xx = boundx;
+        if (xx < 0 || xx > boundx) {
+          xx = x1 + (x1 - xx)
         }

-        if (yy < 0) {
-          y1 -= yy;
-          yy = 0;
-        } else if (yy > boundy) {
-          y1 -= yy - boundy;
-          yy = boundy;
+        if (yy < 0 || yy > boundy) {
+          yy = y1 + (y1 - yy)
         }

Here's my patch, which I think produces better behavior than the others posted. One thing in particular it removes is the pop-to-edge seen in the demo when using minSize and switching sides near the edge.

@@ -578,44 +578,36 @@
         }

         // Magic %-)
-        if (xx > x1) { // right side
+        if (xx >= x1) { // right side
           if (xx - x1 < min_x) {
             xx = x1 + min_x;
           } else if (xx - x1 > max_x) {
             xx = x1 + max_x;
           }
-          if (yy > y1) {
+          if (yy >= y1) {
             yy = y1 + (xx - x1) / aspect;
           } else {
             yy = y1 - (xx - x1) / aspect;
           }
-        } else if (xx < x1) { // left side
+        } else { // left side
           if (x1 - xx < min_x) {
             xx = x1 - min_x;
           } else if (x1 - xx > max_x) {
             xx = x1 - max_x;
           }
-          if (yy > y1) {
+          if (yy >= y1) {
             yy = y1 + (x1 - xx) / aspect;
           } else {
             yy = y1 - (x1 - xx) / aspect;
           }
         }

-        if (xx < 0) {
-          x1 -= xx;
-          xx = 0;
-        } else if (xx > boundx) {
-          x1 -= xx - boundx;
-          xx = boundx;
+        if (xx < 0 || xx > boundx) {
+          xx = x1 + (x1 - xx)
         }

-        if (yy < 0) {
-          y1 -= yy;
-          yy = 0;
-        } else if (yy > boundy) {
-          y1 -= yy - boundy;
-          yy = boundy;
+        if (yy < 0 || yy > boundy) {
+          yy = y1 + (y1 - yy)
         }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文