Jcrop是一个功能强大的图像裁剪引擎

Jcrop是一个功能强大的图像裁剪引擎jQuery的。

它的设计使开发人员可以很容易地直接集成了先进的图像裁剪功能集成到任何基于Web的应用程序在不牺牲动力和灵活性(或编码,测试和调试的星期)。Jcrop还设有干净,组织良好的代码,在大多数现代的web浏览器效果很好。

在<HEAD>你需要加载必要文件的页面 这包括:
jQuery库
Jcrop的Javascript
Jcrop CSS样式表
它应该是这个样子:
  1. <scriptsrc="js/jquery.min.js"></SCRIPT>
  2. <scriptsrc="js/jquery.Jcrop.min.js"></SCRIPT>
  3. <linkrel="stylesheet"href="css/jquery.Jcrop.css"type="text/css"/>

入门第一个简单点的Demo:
  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <metahttp-equiv="Content-Type"content="text/html;charset=ISO-8859-1">
  7. <title>Inserttitlehere</title>
  8. <scriptsrc="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  9. <scriptsrc="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  10. <scriptsrc="js/jquery.Jcrop.min.js"></script>
  11. <linkrel="stylesheet"href="css/jquery.Jcrop.css"type="text/css"/>
  12. <script>
  13. jQuery(function(){
  14. jQuery('#user_preview_img').Jcrop({
  15. trackDocument:true
  16. });
  17. });
  18. </script>
  19. </head>
  20. <body>
  21. <imgalt=""src="images/area1/1.jpg"id="user_preview_img">
  22. </body>
  23. </html>

效果图:

Jcrop是一个功能强大的图像裁剪引擎

jcrop简单的事件处理Demo:

  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <metahttp-equiv="Content-Type"content="text/html;charset=ISO-8859-1">
  7. <title>Inserttitlehere</title>
  8. <scriptsrc="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  9. <scriptsrc="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  10. <scriptsrc="js/jquery.Jcrop.min.js"></script>
  11. <linkrel="stylesheet"href="css/jquery.Jcrop.css"type="text/css"/>
  12. <script>
  13. jQuery(document).ready(function(){
  14. jQuery('#user_preview_img').Jcrop({
  15. onChange:showCoords,
  16. onSelect:showCoords
  17. });
  18. });
  19. //Simpleeventhandler,calledfromonChangeandonSelect
  20. //eventhandlers,aspertheJcropinvocationabove
  21. functionshowCoords(c)
  22. {
  23. jQuery('#x1').val(c.x);
  24. jQuery('#y1').val(c.y);
  25. jQuery('#x2').val(c.x2);
  26. jQuery('#y2').val(c.y2);
  27. jQuery('#w').val(c.w);
  28. jQuery('#h').val(c.h);
  29. };
  30. </script>
  31. </head>
  32. <body>
  33. <div><imgalt=""src="images/area1/1.jpg"id="user_preview_img"></div>
  34. <formonsubmit="returnfalse;"class="coords">
  35. <label>X1<inputtype="text"size="4"id="x1"name="x1"/></label>
  36. <label>Y1<inputtype="text"size="4"id="y1"name="y1"/></label>
  37. <label>X2<inputtype="text"size="4"id="x2"name="x2"/></label>
  38. <label>Y2<inputtype="text"size="4"id="y2"name="y2"/></label>
  39. <label>W<inputtype="text"size="4"id="w"name="w"/></label>
  40. <label>H<inputtype="text"size="4"id="h"name="h"/></label>
  41. </form>
  42. </body>
  43. </html>

效果图:

Jcrop是一个功能强大的图像裁剪引擎

jcrop实例演示Demo3:

  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <metahttp-equiv="Content-Type"content="text/html;charset=ISO-8859-1">
  7. <title>Inserttitlehere</title>
  8. <scriptsrc="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  9. <scriptsrc="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  10. <scriptsrc="js/jquery.Jcrop.min.js"></script>
  11. <linkrel="stylesheet"href="css/jquery.Jcrop.css"type="text/css"/>
  12. <script>
  13. jQuery(document).ready(function(){
  14. jQuery('#user_preview_img').Jcrop({
  15. onChange:showCoords,
  16. onSelect:showCoords,
  17. bgColor:'red',
  18. bgOpacity:.4,
  19. setSelect:[100,100,50,50],
  20. aspectRatio:16/9
  21. });
  22. });
  23. //Simpleeventhandler,calledfromonChangeandonSelect
  24. //eventhandlers,aspertheJcropinvocationabove
  25. functionshowCoords(c)
  26. {
  27. jQuery('#x1').val(c.x);
  28. jQuery('#y1').val(c.y);
  29. jQuery('#x2').val(c.x2);
  30. jQuery('#y2').val(c.y2);
  31. jQuery('#w').val(c.w);
  32. jQuery('#h').val(c.h);
  33. };
  34. </script>
  35. </head>
  36. <body>
  37. <div><imgalt=""src="images/area1/1.jpg"id="user_preview_img"></div>
  38. <formonsubmit="returnfalse;"class="coords">
  39. <label>X1<inputtype="text"size="4"id="x1"name="x1"/></label>
  40. <label>Y1<inputtype="text"size="4"id="y1"name="y1"/></label>
  41. <label>X2<inputtype="text"size="4"id="x2"name="x2"/></label>
  42. <label>Y2<inputtype="text"size="4"id="y2"name="y2"/></label>
  43. <label>W<inputtype="text"size="4"id="w"name="w"/></label>
  44. <label>H<inputtype="text"size="4"id="h"name="h"/></label>
  45. </form>
  46. </body>
  47. </html>

效果图:

Jcrop是一个功能强大的图像裁剪引擎

Jcrop实例Demo4:

  1. <%@pagelanguage="java"contentType="text/html;charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <metahttp-equiv="Content-Type"content="text/html;charset=ISO-8859-1">
  7. <title>Inserttitlehere</title>
  8. <scriptsrc="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  9. <scriptsrc="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  10. <scriptsrc="js/jquery.Jcrop.min.js"></script>
  11. <linkrel="stylesheet"href="css/jquery.Jcrop.css"type="text/css"/>
  12. <scripttype="text/javascript">
  13. jQuery(function($){
  14. //Createvariables(inthisscope)toholdtheAPIandimagesize
  15. varjcrop_api,
  16. boundx,
  17. boundy,
  18. //Grabsomeinformationaboutthepreviewpane
  19. $preview=$('#preview-pane'),
  20. $pcnt=$('#preview-pane.preview-container'),
  21. $pimg=$('#preview-pane.preview-containerimg'),
  22. xsize=$pcnt.width(),
  23. ysize=$pcnt.height();
  24. console.log('init',[xsize,ysize]);
  25. $('#user_preview_img').Jcrop({
  26. onChange:updatePreview,
  27. onSelect:updatePreview,
  28. aspectRatio:xsize/ysize
  29. },function(){
  30. //UsetheAPItogettherealimagesize
  31. varbounds=this.getBounds();
  32. boundx=bounds[0];
  33. boundy=bounds[1];
  34. //StoretheAPIinthejcrop_apivariable
  35. jcrop_api=this;
  36. //Movethepreviewintothejcropcontainerforcsspositioning
  37. $preview.appendTo(jcrop_api.ui.holder);
  38. });
  39. functionupdatePreview(c)
  40. {
  41. if(parseInt(c.w)>0)
  42. {
  43. varrx=xsize/c.w;
  44. varry=ysize/c.h;
  45. $pimg.css({
  46. width:Math.round(rx*boundx)+'px',
  47. height:Math.round(ry*boundy)+'px',
  48. marginLeft:'-'+Math.round(rx*c.x)+'px',
  49. marginTop:'-'+Math.round(ry*c.y)+'px'
  50. });
  51. }
  52. };
  53. });
  54. </script>
  55. <styletype="text/css">
  56. /*Applythesestylesonlywhen#preview-panehas
  57. beenplacedwithintheJcropwidget*/
  58. .jcrop-holder#preview-pane{
  59. display:block;
  60. position:absolute;
  61. z-index:2000;
  62. top:10px;
  63. right:-280px;
  64. padding:6px;
  65. border:1pxrgba(0,0,0,.4)solid;
  66. background-color:white;
  67. -webkit-border-radius:6px;
  68. -moz-border-radius:6px;
  69. border-radius:6px;
  70. -webkit-box-shadow:1px1px5px2pxrgba(0,0,0,0.2);
  71. -moz-box-shadow:1px1px5px2pxrgba(0,0,0,0.2);
  72. box-shadow:1px1px5px2pxrgba(0,0,0,0.2);
  73. }
  74. /*TheJavascriptcodewillsettheaspectratioofthecrop
  75. areabasedonthesizeofthethumbnailpreview,
  76. specifiedhere*/
  77. #preview-pane.preview-container{
  78. width:250px;
  79. height:170px;
  80. overflow:hidden;
  81. }
  82. </style>
  83. </head>
  84. <body>
  85. <div><imgalt=""src="images/area1/1.jpg"id="user_preview_img"></div>
  86. <divid="preview-pane">
  87. <divclass="preview-container">
  88. <imgsrc="images/area1/1.jpg"class="jcrop-preview"alt="Preview"/>
  89. </div>
  90. </div>
  91. </body>
  92. </html>

效果图:

Jcrop是一个功能强大的图像裁剪引擎

注意:有关这些选项的对象的格式的几件事情:
文本值必须加引号(如'红','#CCC“,”RGB(10,10,10)')
数值,包括小数点,不应该被引用。
setSelect带有一个数组,这里表示为一个数组文本
aspectRatio可能是最简单的除以宽度/高度设置
后面没有逗号的最后一个选项

jQuery(function(){
});
全写为
jQuery(document).ready(function(){
});

<wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="font-family:simsun; font-size:14px; line-height:21px"><span style="color:#ff0000"><span style="font-family:simsun; font-size:14px; line-height:21px"></span><wbr style="font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; line-height:21px"></span><wbr style="font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; line-height:21px"></span><wbr style="font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; line-height:21px">3.常用选项设置</span></wbr></wbr></wbr></span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">aspectRatio:选中区域按宽/高比,为1表示正方形。</span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">minSize:最小的宽,高值。</span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">maxSize:最大的宽,高值。</span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">setSelect:设置初始选中区域。</span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">bgColor:背景颜色</span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">bgOpacity:背景透明度。</span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">allowResize:是否允许改变选中区域大小。</span><br style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px"></span><wbr style="color:rgb(73,73,73); font-family:simsun; font-size:14px; line-height:21px"><span style="font-family:simsun; font-size:14px; color:#494949; line-height:21px">allowMove:是否允许移动选中区域。</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

  1. $(function(){
  2. $("#demoImage").Jcrop({
  3. aspectRatio:1,//选中区域宽高比为1,即选中区域为正方形
  4. bgColor:"#ccc",//裁剪时背景颜色设为灰色
  5. bgOpacity:0.1,//透明度设为0.1
  6. allowResize:false,//不允许改变选中区域的大小
  7. setSelect:[0,0,100,100]//初始化选中区域
  8. }
  9. );
  10. }
  11. );


4.api用法

var<wbr>api<wbr></wbr></wbr>=<wbr>$.Jcrop(</wbr>"#demoImage");
api.disable();<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
//设置为禁用裁剪效果
api.enable();<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>//设置为启用裁剪效果
api.setOptions({allowResize:false});//设置相应配置
api.setSelect([0,0,100,100]);<wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>//设置选中区域

  1. $(function(){
  2. //事件处理
  3. $("#demoImage").Jcrop(
  4. {
  5. onChange:showCoords,//当选择区域变化的时候,执行对应的回调函数
  6. onSelect:showCoords//当选中区域的时候,执行对应的回调函数
  7. }
  8. );
  9. }
  10. );
  11. functionshowCoords(c){
  12. $("#txtX1").val(c.x);//得到选中区域左上角横坐标
  13. $("#txtY1").val(c.y);//得到选中区域左上角纵坐标
  14. $("#txtX2").val(c.x2);//得到选中区域右下角横坐标
  15. $("#txtY2").val(c.y2);//得到选中区域右下角纵坐标
  16. $("#txtWidth").val(c.w);//得到选中区域的宽度
  17. $("#txtHeight").val(c.h);//得到选中区域的高度
  18. }