jQuery如何为Jcrop添加缩放功能

标签 jquery jcrop

JCrop 这是一个非常棒的插件,但不幸的是缺乏放大缩小功能。

我想知道是否有人尝试过在 jCrop 中添加放大缩小功能。

请发布代码示例。

谢谢

最佳答案

这是一种非常快速且肮脏的方法...... 在 Jcrop 提供的名为“crop.php”的演示文件中,您将找到此函数:

$(function(){
   $('#cropbox').Jcrop({
      aspectRatio: 1,
      onSelect: updateCoords
   });
});

Delete the entire function above and replace it with this:

$(function(){

   var scalex = $('#scalex').val();
   var scaley = $('#scaley').val();
   var myJcrop = $.Jcrop('#cropbox', {
       aspectRatio: 1,
       onSelect: updateCoords,
       boxWidth: scalex, 
       boxHeight: scaley
   });

   $('#target').click(function() {
      myJcrop.destroy();
      scalex = $('#scalex').val();
      scaley = $('#scaley').val();
      myJcrop = $.Jcrop('#cropbox', {
          aspectRatio: 1,
          onSelect: updateCoords,
          boxWidth: scalex, 
          boxHeight: scaley
      });
   });

});

Then add this somewhere in the body:

Scale X:<input type="text" id="scalex" value="150" style="width:50px;"></input>
Scale Y:<input type="text" id="scaley" value="140" style="width:50px;"></input>
<button id="target">Resize Image</button>

关于jQuery如何为Jcrop添加缩放功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5487546/

相关文章:

jquery - 我图像中的信息窗口对话框气球

javascript - Angular 不安全的网址

javascript - 使用jCrop时如何使头像预览图像流畅

ruby-on-rails-3 - 回形针在使用S3时在本地查找文件以进行重新处理

javascript - 如何知道点击了哪个链接/按钮,然后替换内容?

javascript - 使用后退按钮和 Ajax Dom 操作保持滚动位置

jquery - 如何将所需的文本添加到 jQuery 分页插件

javascript - 添加一个类并删除当前类,以便 J Query 中的按钮可以重新用于不同的功能

jquery - Rails3 Paperclip JCrop 进入循环

javascript - JQuery 上传、预览、裁剪