简体   繁体   English

错误的位置imgAreaSelect插件在bootstrap模式窗口中

[英]Wrong position imgAreaSelect plugin in bootstrap modal window

I have a problem with imgAreaSelect plugin in Bootstrap. 我在Bootstrap中遇到了imgAreaSelect插件的问题。 I set parent in initializing imgAreaSelect to prevent scroll moving area : 我在初始化imgAreaSelect时设置父级以防止滚动移动区域:

 thumb.imgAreaSelect({
 handles: true,
 aspectRatio: '1:1',
 fadeSpeed: 300,
 parent: "#thumbBox"
 })

and this is my html : 这是我的HTML:

<div class="modal-body">
            <div class="row">
                <div class="col-xs-12" style="font-weight:bold;">
                    Upload your picture and crop it.
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <div id="thumbBox">
                        <img id="thumb" class="img-responsive" />
                    </div>
                </div>
            </div>

whene I trying to select an area,ImgAreaSelect selects an area outside the picture but points ( I mean x1,x2 etc) are exactly that I want(the functionality works correct but in interface there is problem). 当我试图选择一个区域时,ImgAreaSelect选择图片外的区域但是点(我的意思是x1,x2等)正是我想要的(功能正常但在界面中有问题)。 In smaller devices's,ImgAreaSelect interface is nit but in some situation it mess up ! 在较小的设备中,ImgAreaSelect接口是尼特,但在某些情况下它会搞砸! I used to search a lot but i didn't find anything useful. 我曾经搜索过很多,但我找不到任何有用的东西。 How can i fix this problem ? 我该如何解决这个问题?

UPDATE : I solved this My self... Refer to this link : github 更新:我解决了这个我自己......请参阅此链接: github

We must remove these lines from code : 我们必须从代码中删除这些行:

/* Also check if any of the ancestor elements has fixed position */ 
        if ($p.css('position') == 'fixed')
           position = 'fixed';

And we must position relative the parent box that we initialized ourselves( parent: "#thumbBox"). 我们必须相对于我们自己初始化的父框(父级:“#thumbBox”)。

Had same problem. 有同样的问题。 solution was: 解决方案是:

parent:$('.modal-content')

you need to set modal content as parent not image container. 您需要将模态内容设置为父级而不是图像容器。

I mean the parent div of Image that you want to use image area select on it , must be position relative . 我的意思是想要在其上使用图像区域选择的Image的父div,必须是位置相对的。

 <div id="thumbBox" style="position:relative;">
     <img id="thumb" class="img-responsive" />
   </div>

And We must remove these lines from jquery.imageareaselect.js : 我们必须从jquery.imageareaselect.js中删除这些行:

/* Also check if any of the ancestor elements has fixed position */ 
        if ($p.css('position') == 'fixed')
           position = 'fixed';

There are several scenarios that bootstrap.css can affect your imgareaselect. 有几种情况,bootstrap.css会影响你的imgareaselect。 For me setting box-sizing:content-box on the image fixed my problem. 对我来说,设置框大小:图像上的内容框修复了我的问题。

<img id="cartPhoto" class="cartImageThumb" style="box-sizing:content-box; -moz-box-sizing:content-box; -webkit-box-sizing:content-box;">

I prefer to overwrite the css inline vs modifying the bootstrap.css file because those chan it can affect the whole system. 我更喜欢覆盖css内联和修改bootstrap.css文件,因为它可以影响整个系统。

If you run into issues with bootstrap.css affecting your code, comment out sections of bootstrap.css until you find which style is affecting you. 如果遇到影响代码的bootstrap.css问题,请注释掉bootstrap.css的各个部分,直到找到影响你的样式。

HTML: HTML:

<div><img id="cropimage" /></div>

JQUERY: JQUERY:

$(function () {
 $('#cropimage').imgAreaSelect({ handles: true, parent: "cropimage", maxWidth: 200, maxHeight: 200, aspectRatio: '4:3' });
});

SOLUTION: 解:

Use "parent" option to fix the imgAreaSelect to a parent div/window. 使用“parent”选项将imgAreaSelect修复为父div /窗口。

People who are having trouble with this in combination with Bootstrap 2 Bootstrap 2结合使用时遇到问题的人

Go to bootstrap.css and comment out the following line 转到bootstrap.css并注释掉以下行

img {
    width: auto\9;
    height: auto;
    /* max-width: 100%; DISABLE FOR IMGAREASELECT */
    vertical-align: middle;
    border: 0;
    -ms-interpolation-mode: bicubic;
}

I had the same issue. 我遇到过同样的问题。 I was looked for a solution on this thread, trying all options. 我在这个线程上寻找解决方案,尝试所有选项。 But, when I read the documentation I found this 2 properties: 但是,当我阅读文档时,我发现了这2个属性:

http://odyniec.net/projects/imgareaselect/usage.html http://odyniec.net/projects/imgareaselect/usage.html

imageHeight - True height of the image (if scaled with the CSS width and height properties) 
imageWidth - True width of the image (if scaled with the CSS width and height properties) 

So, there is no need to change any code of js or css. 因此,无需更改任何js或css代码。 The only thing to do is set these 2 properties with the real size of the image. 唯一要做的就是使用图像的实际大小设置这两个属性。

Something like this: 像这样的东西:

var image = $("#image");

image.imgAreaSelect({
    imageHeight: image[0].naturalHeight,
    imageWidth: image[0].naturalWidth
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM