【问题标题】:Wrong position imgAreaSelect plugin in bootstrap modal window引导模式窗口中的错误位置 imgAreaSelect 插件
【发布时间】:2013-12-17 08:19:03
【问题描述】:

我在 Bootstrap 中遇到了 imgAreaSelect 插件的问题。 我在初始化 imgAreaSelect 时设置了父级以防止滚动移动区域:

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

这是我的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>

当我尝试选择一个区域时,ImgAreaSelect 会选择图片之外的一个区域,但点(我的意思是 x1、x2 等)正是我想要的(功能正常但在界面中有问题)。 在较小的设备中,ImgAreaSelect 界面是 nit 但在某些情况下它会搞砸! 我曾经搜索了很多,但我没有找到任何有用的东西。 我该如何解决这个问题?

更新: 我解决了这个我自己... 参考这个链接: github

我们必须从代码中删除这些行:

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

我们必须相对于我们自己初始化的父框定位(父:“#thumbBox”)。

【问题讨论】:

  • 太好了,这个修复 imgAreaSelect 插件也在一个基础上显示。谢谢
  • 你在哪里删除这些行?遇到同样的问题
  • imgAreaSelect 未接受此修复是否有原因?
  • 您解决了这个问题吗?它仍然完全处于错误的位置:(欢迎任何帮助!
  • 你是否从js中删除了代码的和平?

标签: javascript jquery html css twitter-bootstrap


【解决方案1】:

我有同样的问题。我在这个线程上寻找解决方案,尝试所有选项。 但是,当我阅读文档时,我发现了这两个属性:

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) 

因此,无需更改任何 js 或 css 代码。 唯一要做的就是将这 2 个属性设置为图像的实际大小。

类似这样的:

var image = $("#image");

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

【讨论】:

    【解决方案2】:

    我的意思是你想在它上面使用图像区域选择的Image的父div,必须是相对位置的。

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

    我们必须从 jquery.imageareaselect.js 中删除这些行:

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

    【讨论】:

      【解决方案3】:

      有同样的问题。 解决方案是:

      parent:$('.modal-content')
      

      您需要将模态内容设置为父容器而不是图像容器。

      【讨论】:

      • 我已经测试了 cmets 中提出的所有解决方案,这个对我有用,不需要修改任何库
      • 这对我也有用。这应该被选为正确的答案,因为它实现起来非常简单,也很直观。
      【解决方案4】:

      HTML:

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

      JQUERY:

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

      解决方案:

      使用“父”选项将 imgAreaSelect 固定为父 div/窗口。

      【讨论】:

        【解决方案5】:

        bootstrap.css 会在多种情况下影响您的 imgareaselect。对我来说,在图片上设置 box-sizing:content-box 解决了我的问题。

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

        我更喜欢覆盖内联的 css 而不是修改 bootstrap.css 文件,因为它会影响整个系统。

        如果您遇到影响代码的 bootstrap.css 问题,请注释掉 bootstrap.css 的部分,直到找到影响您的样式。

        【讨论】:

          【解决方案6】:

          结合 Bootstrap 2 遇到此问题的人

          转到 bootstrap.css 并注释掉以下行

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

          【讨论】:

          • 当然这解决了这个问题,但是有没有办法将 imgAreaSelect 与 max-width 一起使用?我认为必须有任何方法可以在调整大小的预览图像上进行选择,但在计算正确的坐标之后。我就是做不到。有什么想法吗?
          • 我试过了,但这不是简单的数学运算。您必须知道图像被缩放的像素数量,然后将该数量应用于 imgareaselect。我现在所做的是当用户上传图像时,它首先被重新缩放。然后用户可以使用 imgareaselect,但是我首先重新调整它以适应每个屏幕
          • +1 虽然它确实是一个“不好”的解决方案,但它是我能找到的唯一能够真正解决的问题(至少暂时解决问题)。我仍然会继续寻找更好的解决方案,但到目前为止就是这样,谢谢。
          • 您可以在 imgareaselect 中编辑代码,以便它为 容器提供一个类。然后您可以使用 img.imgareaselect {max-width: auto;}(未经测试)跨度>
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-08-04
          • 2014-07-28
          • 2020-05-18
          • 2016-04-25
          • 1970-01-01
          相关资源
          最近更新 更多