jcrop原始下载页面:猛击此处
基本使用方法如下:
一、在head部分(<head>和</head>之间)插入相关css和js文件。
<link rel=”stylesheet” href=”css/jquery.Jcrop.css”>
<script src=”js/jquery.js”></script>
<script src=”js/jquery.Jcrop.js”></script>
二、在head部分插入回调函数等相关处理参数。
<script language=”Javascript”>
<!–
jQuery(function($){
// Create variables (in this scope) to hold the API and image size
var jcrop_api, boundx, boundy;
$(‘#cropbox’).Jcrop({
minSize: [0,0],
maxSize:[0,0],
setSelect: [0,0,0,0],
boxWidth:800,
borderOpacity:0.3,
keySupport:false,
dragEdges:false,
allowSelect:false,
allowResize:false,
bgOpacity:0.2,
boundary:0,
//allowMove:false,
addClass: ‘jcrop-handle’,
onSelect: updateCoords,
},
function(){
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
// Store the API in the jcrop_api variable
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(‘请选择裁剪区域’);
return false;
};
});
–>
</script>
三、给相关图片加上id以便识别。
<img id=”cropbox” src=”x.jpg”>
这样就能实现最简单的裁剪效果,至于如何结合php等动态语句处理图片,在置顶的文章里已经给出了示例。
下表给出基本options参数设置:
| 名称 | 默认值 | 说明 |
|---|---|---|
| allowSelect | true | 允许新选框 |
| allowMove | true | 允许选框移动 |
| allowResize | true | 允许选框缩放 |
| trackDocument | true | |
| baseClass | “jcrop” | 基础样式名前缀。说明:class=”jcrop-holder”,更改的只是其中的 jcrop。 |
| addClass | null |










