私は jCrop プレビュー デモを使用して自分のことをしています。しかし、私は問題に遭遇しました。を使用して画像が読み込まれるときにデフォルトの選択を作成するとsetSelect:
、選択が大きな画像にマップされますが、プレビューには表示されません。jCrop のロード時に updatePreview 関数を呼び出す API ハンドラが見つかりません。jCropがロードされたときにこの関数を呼び出す方法を知っている人はいますか?
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'
});
}
};
});