如何删除jcrop?

时间:2010-12-16 23:22:47

标签: jquery jcrop

如何解读图像?

我正在添加jcrop;

$('#imgThumbnailer').Jcrop({
    onChange: statusCrop,
    onSelect: statusCrop,
    bgColor: 'black',
    bgOpacity: .3
});

如何解除它?

编辑:

$('#imgThumbnailer').attr("src", $obj.attr('thumbnailer_link'));

var dlg = $("#ThumbnailDialog").dialog({
    modal: false,
    draggable: false,
    position: 'center',
    zIndex: 99999,  // Above the overlay
    closeText: '',
    width: 510,
    height: 500,
    open: function () {
        $('body').css("overflow", "hidden");
        if ($.browser.msie) {
            $('html').css("overflow", "hidden");
        }
        $("#loader").show();

        var ratio = parseFloat($obj.attr('thumbnailer_ratio'));
        jcrop_api = $.Jcrop('#imgThumbnailer', {
            onChange: statusCrop,
            onSelect: statusCrop,
            bgColor: 'black',
            bgOpacity: .3,
            aspectRatio: ratio
        });

    },
    close: function () { $('body').css("overflow", "auto"); if ($.browser.msie) { $('html').css("overflow", "auto"); } $("#loader").hide(); },
    buttons: {
        'Set Thumbnail': function () {
            $(this).dialog('close');
        },
        Cancel: function () {
            jcrop_api.destroy();
            jcrop_api = null;
            $(this).dialog('close');
        }
    }
}).parent();
dlg.appendTo(jQuery('form:first'));

以上代码对我不起作用。我认为这与我在jquery对话框中使用它的事实有关。 http://code.google.com/p/jcrop/issues/detail?id=21

不确定如何修复它。

3 个答案:

答案 0 :(得分:75)

我想知道同样的事情,在阅读源代码后发现了一个在v0.9.8中有效的简单解决方案(其他已发布的答案仅适用于当前的dev版本)。如果你这样启动Jcrop:

$('#imgThumbnailer').Jcrop({
    onChange: statusCrop,
    onSelect: statusCrop,
    bgColor: 'black',
    bgOpacity: .3
});

然后您可以通过以下方式访问api并销毁Jcrop:

JcropAPI = $('#imgThumbnailer').data('Jcrop');
JcropAPI.destroy();

对于提问者来说可能为时已晚,但希望这对从谷歌偶然发现此页面的人有所帮助!

答案 1 :(得分:28)

编辑:在将jcrop添加到图像时,您似乎需要维护对api的引用。

// assign jcrop to jcrop_api
var jcrop_api = $.Jcrop('#imgThumbnailer', {
    onChange: statusCrop,
    onSelect: statusCrop,
    bgColor: 'black',
    bgOpacity: .3
});


// when you want to remove it
jcrop_api.destroy();

答案 2 :(得分:3)

从Jcrop的v0.9.9版本开始,您需要按照以下方式执行此操作:

var jcrop_api;
$('#target').Jcrop(options,function(){
    jcrop_api = this;
});

由创作者提供:http://deepliquid.com/content/Jcrop_API.html