嘗試this JSFiddle
HTML:
<img id="cropbox" src="http://homepage.mac.com/davydewit/popacademie/rw_common/themes/blendit/images/header/image1.jpg" />
<br />
<br />
<div id="previewcrop">
<img id="preview" src="http://homepage.mac.com/davydewit/popacademie/rw_common/themes/blendit/images/header/image1.jpg" />
</div>
CSS:
#previewcrop{
width: 100px;
height: 100px;
overflow: hidden;
margin-left: 5px;
}
JS:
var imgwidth = 849; // width of the image
var imgheight = 423; // height of the image
jQuery('#cropbox').Jcrop({
onChange: showPreview,
onSelect: showPreview,
bgColor: 'white',
aspectRatio: 1,
boxWidth: imgwidth/3,
boxHeight: imgheight/3
});
function showPreview(coords)
{
var rx = 100/coords.w;
var ry = 100/coords.h;
$('#preview').css({
width: Math.round(rx * imgwidth) + 'px',
height: Math.round(ry * imgheight) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
};