jQuery.jcrop 基本参数

来源:互联网 发布:便签软件下载 编辑:程序博客网 时间:2024/05/16 01:23

<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);  };  function checkCoords()  {  if (parseInt($('#w').val())) return true;  alert('请选择裁剪区域');  return false;  };  });--></script>

基本使用方法如下:

一、在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部分插入回调函数等相关处理参数


三、给相关图片加上id以便识别。

 <img id="cropbox" src="x.jpg">

这样就能实现最简单的裁剪效果,至于如何结合php等动态语句处理图片,在置顶的文章里已经给出了示例。

下表给出基本options参数设置:

名称默认值说明allowSelecttrue允许新选框allowMovetrue允许选框移动allowResizetrue允许选框缩放trackDocumenttrue baseClass"jcrop"基础样式名前缀。说明:class="jcrop-holder",更改的只是其中的 jcrop。addClassnull添加样式会。例:假设值为 "test",那么会添加样式到 class="test jcrop-holder"bgColor"black"背景颜色。颜色关键字、HEX、RGB 均可。bgOpacity0.6背景透明度bgFadefalse使用背景过渡效果borderOpacity0.4选框边框透明度handleOpacity0.5缩放按钮透明度handleSize9缩放按钮大小handleOffset5缩放按钮与边框的距离aspectRatio0选框宽高比。说明:width/heightkeySupporttrue支持键盘控制。按键列表:上下左右(移动)、Esc(取消)、Tab(跳出裁剪框,到下一个)cornerHandlestrue允许边角缩放sideHandlestrue允许四边缩放drawBorderstrue绘制边框dragEdgestrue允许拖动边框fixedSupporttrue touchSupportnull boxWidth0画布宽度boxHeight0画布高度boundary2边界。说明:可以从边界开始拖动鼠标选择裁剪区域fadeTime400过度效果的时间animationDelay20动画延迟swingSpeed3过渡速度minSelect[0,0]选框最小选择尺寸。说明:若选框小于该尺寸,则自动取消选择maxSize[0,0]选框最大尺寸minSize[0,0]选框最小尺寸onChangefunction(){}选框改变时的事件onSelectfunction(){}选框选定时的事件onReleasefunction(){}取消选框时的事件

下表是api方法

名称说明setImage(string)设定(或改变)图像。例:jcrop_api.setImage("newpic.jpg")setOptions(object)设定(或改变)参数,格式与初始化设置参数一样setSelect(array)创建选框,参数格式为:[x,y,x2,y2]animateTo(array)用动画效果创建选框,参数格式为:[x,y,x2,y2]release()取消选框disable()禁用 Jcrop。说明:已有选框不会被清除。enable()启用 Jcropdestroy()移除 JcroptellSelect()获取选框的值(实际尺寸)。例子:console.log(jcrop_api.tellSelect())tellScaled()获取选框的值(界面尺寸)。例子:console.log(jcrop_api.tellScaled())getBounds()获取图片实际尺寸,格式为:[w,h]getWidgetSize()获取图片显示尺寸,格式为:[w,h]getScaleFactor()获取图片缩放的比例,格式为:[w,h]



原创粉丝点击