我正在使用jCrop预览演示来做我自己的事情。但是我遇到了一个问题。如果我使用setSelect:
加载图像时创建默认选择,那么我将选择映射到大图像上,但它不会出现在预览中。当jCrop加载时,我无法找到调用updatePreview函数的api处理程序。有没有人知道如何在jCrop加载时调用这个函数?jCrop - 更新预览onload?
jQuery(function($){
// Create variables (in this scope) to hold the API and image size
var jcrop_api, boundx, boundy;
$('#target').Jcrop({
onChange: updatePreview,
onSelect: updatePreview,
setSelect: [ 0, 0, selectWidth, selectHeight ],
aspectRatio: 1
},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 updatePreview(c)
{
if (parseInt(c.w) > 0)
{
var rx = 100/c.w;
var ry = 100/c.h;
$('#preview').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'
});
}
};
});
好哆嗦我木材。这很烦人。感谢您指出我在正确的方向 – JasonS