我正在尝试replicate this jcrop demo。一切都很好,除了我的原始图片非常大,所以,在我的页面上的as per the manual, i am resizing them如下:
jQuery('#cropbox').Jcrop({
onChange: showPreview,
onSelect: showPreview,
bgColor: 'white',
aspectRatio: 1,
boxWidth: 300,
boxHeight: 500
});现在的问题是第二个预览窗口(id=“预览”)不再显示裁剪框上裁剪部分的内容。下面是一个示例:

显然,预览窗口与我在第一张图片中裁剪的区域不匹配。
当你预先调整主图像的大小时,你知道如何让预览图像正确显示吗?
发布于 2010-11-09 17:54:34
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'
});
};发布于 2010-11-04 13:17:34
function showPreview(coords)
{
if (parseInt(coords.w) > 0)
{
var rx = 100 / coords.w;
var ry = 100 / coords.h;
jQuery('#preview').css({
width: Math.round(rx * 800) + 'px',
height: Math.round(ry * 600) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
}
}对于(rx * 800),800应该是真实图像的宽度。对于(ry * 600),600应该是真实图像的宽度。我已经在一张800x600的图像上测试了它,它可以工作(使用Tutorial3.html并修改它)。此外,不要使用缩放图像的宽度和高度,它将不起作用。
https://stackoverflow.com/questions/4070731
复制相似问题