JavaScript图像裁剪问题

JavaScript图像裁剪问题,javascript,Javascript,我用这段代码来选择需要裁剪的图像区域 function preview(img, selection) { var scaleX = 100 / selection.width; var scaleY = 100 / selection.height; $('#thumbnail + > img').css({ width: Math.round(scaleX * 354) + 'px', height: Math.round(scaleY * 448) + 'px', marginLe

我用这段代码来选择需要裁剪的图像区域

function preview(img, selection) {
var scaleX = 100 / selection.width;
var scaleY = 100 / selection.height;

$('#thumbnail + > img').css({
width: Math.round(scaleX * 354) + 'px',
height: Math.round(scaleY * 448) + 'px',
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
});
$('#x1').val(selection.x1);
$('#y1').val(selection.y1);
$('#x2').val(selection.x2);
$('#y2').val(selection.y2);
$('#w').val(selection.width);
$('#h').val(selection.height);
}


$(window).load(function () {
$('#thumbnail').imgAreaSelect({ x1: 120, y1: 90, x2: 280, y2: 210, aspectRatio: '1:1', onSelectChange: preview });

});
这很好,但我使用标签来显示不同的部分。当我点击下一个标签时,我可以看到我不想要的图像裁剪器。我如何解决这个问题?

嗨,
我认为您正在使用div作为图像裁剪器。如果是这种情况,您可以在单击其他选项卡时设置div属性style.display='none'。

我看到您使用了$function,但这不是标准的JavaScript。如果您使用的是Prototype、JQuery、Dojo或其他JavaScript框架,您应该在问题中提到这一点。此外,尝试将代码放入代码块中(请参见编辑器面板顶部的按钮)