我在我的應用程序中使用Jcrop插件(JQuery)。我決定使用一些Ajax解決方案,但在傳遞值的功能方面存在問題。我不知道是否我缺乏JavaScript技能或Jcrop問題。 這裏是代碼Jcrop中的多張圖片和prewievs。如何通過許多ID的JavaScript函數
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'
});
}
}
工作有一個畫面例子是在這裏: link text
我要的是通過多個參數的功能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'
});
}
}
但出現錯誤。如何解決?
偉大的解決方案! – 2012-05-16 04:08:53
非常感謝! – 2013-05-14 14:03:48
你救了我的命<3雖然Jcrop的文檔可能會更好:'( – NealVDV 2016-07-12 20:28:53