3

我正在使用 jQuery 插件 Jcrop。我对名为 setSelect 的初始设置之一有疑问。

该属性接受具有两组 x 和 y 坐标(左上角和右下角)的数组。

<img src="blah" id="cropTool" />
<script type="text/javascript">
    $(function()
    {
        $('#cropTool').Jcrop(
        {
            setSelect: [
                $('#cropTool').width()/4,
                $('#cropTool').height()/4,
                ($('#cropTool').width()/4)*3,
                ($('#cropTool').height()/4)*3
            ]
        });
    });
</script>

从视觉上看,这完全符合我的预期。它放置一个裁剪选择,左上角 1/4 进入图像(x 和 y),右下角 1/4 从图像右下角进入图像。像这样:

http://www.codetunnel.com/content/images/VisuallyFine.jpg

但是当我去移动它时,它会跳到这个位置:

http://www.codetunnel.com/content/images/Jumps.jpg

它立即跳到那里,我没有把它拖到那里。如果我尝试拖动默认选择,它会在移动一个像素或更多像素后跳转。在它跳跃后,我可以正常移动它。这是一个小问题,但很烦人。

有任何想法吗?

4

2 回答 2

1

Turns out another jQuery plugin I was using was interfering with the jcrop positioning. A plugin called colorbox which loads overlay popups was the issue. I was calling jQuery.colorbox.resize() right before I was calling jcrop. When the jcrop code ran the resize was never quite complete. One solution was to put the jcrop code into a setTimeout() to delay the code for a second. That was hackish solution so I asked another more specific question and got an answer. Turns out another fork of colorbox contains a fix to include a function callback on the resize method so that you can execute code when the resize is complete.

jQuery colorbox plugin resize callback

于 2011-07-18T20:18:24.620 回答
0

不确定这是否完全正确,您只是从您的来源复制/粘贴,但这里有一个错字:

$('#ropTool').height()/4,

您可能正在寻找 $('#cropTool').height()/4,

于 2011-07-13T17:25:26.590 回答