jcrop简单实例
1. 首先从官方网站上下载jcrop压缩包, 解压缩将js和css文件放入项目路径 [url]http://deepliquid.com/content/Jcrop_Download.html[/url] 2. 代码实例: [code="html"] jcrop.html


[/code] 3. 通过jquery自定义插件对其进行简单的封装 [code="js"](function($){ $.fn.myJcrop=function(opts){ console.log($(this)); var jcrop_api,boundx,boundy, $preview=$("#preview-pane"), $pcnt=$("#preview-pane .preview-container"), $pimg=$("#preview-pane .preview-container img"), xsize=$pcnt.width(), ysize=$pcnt.height(); var setting=$.extend({ onChange:updatePreview, onSelect:updatePreview, aspectRatio:xsize/ysize, },opts||{}); $(this).Jcrop(setting,function(){ var bounds=this.getBounds(); boundx=bounds[0]; boundy=bounds[1]; jcrop_api = this; $("#preview-container").appendTo(jcrop_api.ui.holder); }); function updatePreview(c) { if (parseInt(c.w) > 0) { var rx = xsize / c.w; var ry = ysize / c.h; //让节点发生改变,也就是预览图#preview节点 $pimg.css({ width : Math.round(rx * boundx) + 'px', height : Math.round(ry * boundy) + 'px', marginLeft : '-' + Math.round(rx * c.x) + 'px', marginTop : '-' + Math.round(ry * c.y) + 'px' }); } } }; })(jQuery);[/code] 通过 $("#target").myJcrop({setSelect:[0,0,490,120]}); 即可完成调用