jquery - Jcrop 加载后压缩图像,应用错误的宽度

标签 jquery ajax image crop jcrop

我使用Jcrop来编辑用户上传的图像,当用户决定编辑他们的图像时,会进行AJAX调用来获取用户的原始图像,我的代码如下:

var jcrop_api;

$('.edit_image').on('click', function(e)
{
  var url = $(this).attr('data-url');

  e.preventDefault();

  $.ajax({
    url: url,
    type: 'GET',
    cache: false,
    beforeSend: function()
    {
      // Remove old box in case user uploaded new image bring the latest one
      $('#edit_box').remove();
    },
    success: function(result)
    { 
      if (result.error)
      {
        alert(result.error);
      }
      else
      {

        $('.edit_image_box').html(result);
        $('#edit_box').modal({ show: true});

        $('#original_img').load( function()
        {
          $(this).Jcrop({
            aspectRatio: 1,
            onSelect: updateCoords,
            boxWidth: 700,
            boxHeight: 700
          }, function()
          {
            jcrop_api = this;
          });
        });
      }
    }
  })
});

function updateCoords(c)
{
  $('#x').val(c.x);
  $('#y').val(c.y);
  $('#w').val(c.w);
  $('#h').val(c.h);
};

function checkCoords()
{
  if (parseInt($('#w').val())) return true;
  alert('Please select a crop region then press submit.');
  return false;
};

盒子被加载,模态被显示,图像被完美加载,但是一旦完成加载并且 Jcrop 开始播放,它会完全缩小宽度,留下大约 20px 宽的图像。

有人可以帮我解决这个问题吗,几乎 80% 的情况都会发生这种情况。干杯!

最佳答案

我找到了解决方案,问题是使用响应式网格,我使用 Twitter 的 Bootstrap 模式来显示图像裁剪,并且正文的 css 设置为 max-width: 100%;这个设置在获取图像的宽度和高度时使 Jcrop 感到困惑。因此,要解决这个问题,唯一需要做的就是使用 .jcrop 类或您喜欢的任何内容将图像包装在 DIV 中,并将 css 设置为:

.jcrop img {
   max-width: none;
}

这将解决问题,现在如果有人知道如何使 Jcrop 响应,我将非常感谢您的帮助。这里有更详细的讨论github pull

干杯!

关于jquery - Jcrop 加载后压缩图像,应用错误的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16451108/

相关文章:

javascript - 缩放和平移 HTML5 Canvas - 库

javascript - Ajax 请求未重定向到 URL

image - Unity-3d-5 缩放图像 16 :9 to other resolutions

html - 具有最大宽度/高度且没有 CSS 的 HTML 中的响应图像

jquery - 没有文字时如何去除边框

javascript - 如何将图像或图标添加到 JQuery Accordion 的 h3 标签中

Ajax XMLHttpRequest 对象限制

java - 在 Java 中旋转 tiff 图像的最干净、最有效的技术?

jquery - .load 和 .html 出现问题 - 尝试刷新 div 以显示 google AdSense

javascript - 始终从第一种形式获取值。怎么了?