jQuery how to add to Jcrop zoom feature

六月ゝ 毕业季﹏ 提交于 2019-12-06 07:13:49

问题


JCrop it is a really great plugin but unfortunately lack of Zoom-In Zoom-Out feature.

I would like to know if someone have ever tried to add a Zoom-In Zoom-Out feature in jCrop.

Please post an example of code.

Thanks


回答1:


This is a very quick and dirty way to do it... In the demo file provided with Jcrop called "crop.php" you'll find this function:

$(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>



回答2:


This is great:

https://github.com/sheldon/jquery-cropzoom



来源:https://stackoverflow.com/questions/5487546/jquery-how-to-add-to-jcrop-zoom-feature

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!