アプリでJcropプラグイン(Jquery)を使用しています。私はいくつかのajaxソリューションを使用することにしましたが、関数に値を渡すことに問題があります。JavaScriptのスキルが不足しているのか、Jcropの問題なのかわかりません。コードは次のとおりです。
jQuery(window).load(function(){
jQuery('#cropbox').Jcrop({
onChange: showPreview,
onSelect: showPreview,
aspectRatio: 1
});
});
// Our simple event handler, called from onChange and onSelect
// event handlers, as per the Jcrop invocation above
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 * 500) + 'px',
height: Math.round(ry * 370) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
}
}
1枚の写真を使った作業例は次のとおりです。
リンクテキストhttp://deepliquid.com/projects/Jcrop/demos.php?demo=thumbnail
私が欲しいのは、次のような関数showPreview(coords)に複数のパラメーターを渡すことです。
function showPreview(coords,id,size_x,size_y)
{
if (parseInt(coords.w) > 0)
{
var rx = 100 / coords.w;
var ry = 100 / coords.h;
jQuery('#'+id).css({
width: Math.round(rx * size) + 'px',
height: Math.round(ry * size_y) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
}
}
しかし、エラーが表示されます。それを解決する方法は?