2010-03-05 76 views
14

所以即時通訊使用這個整潔的jQuery插件http://odyniec.net/projects/imgareaselect/ 它工作正常,但我用jquery ui回調函數(對話框)引發它,我需要在對話框關閉後刪除選擇。從元素中刪除jquery imgareaselect插件

function initialize_selection() { 
$('#image_area').imgAreaSelect({ x1: 10, y1: 10, x2: $('#image_area').width()-10, y2: $('#image_area').height()-10 , fadeSpeed: 400, handles: true}); 
} 

$(function() { 
$('#image_edit').click(function(){ 
    $('#edit_image_dialog').load('actions.php?action=edit_temp_image', function(){ 
      $('#edit_image_dialog').dialog({ 
       modal: true, 
       resizable: false, 
       width: 480, 
        buttons: { 
      Ok: function() { 
         //foo_bar                   
      }, 
         Cancel: function() { 
         //foo_bar 
      } 
        }, 
        beforeclose: function(){ 
        //What should i put here ??? 
        ;} 
      }); 
    initialize_selection(); 
     }); 
    }); 
}); 

我真的很感激一些提示,因爲我是新來的jquery,我不能自己解決這個問題。

謝謝

+0

不確定,但+1分享一個非常酷的jQuery插件的問題! – 2010-03-05 13:32:44

回答

0

它真的工作,但後 - > $('#image_area')。imgAreaSelect({remove:true}); 它不能正常工作的標記其他照片

5

我發現得到去除選擇治療領域的唯一途徑是以下幾點:

"Close": function() { 
    $(".imgareaselect-selection").parent().remove(); 
    $(".imgareaselect-outer").remove(); 
    $(this).dialog("close"); 
}, 

下並沒有爲我工作(在jQuery和jQueryUI的在WordPress的3.0.5元素)

$(selector).imgAreaSelect({remove: true}); 
+2

+1。 $(selector).imgAreaSelect({remove:true});沒有爲我工作。 – 2012-06-20 04:38:18

4

這爲我工作:

var $ias = $('#imageArea').imgAreaSelect({ 
    instance: true 
}); 

$('#clearBtn2').click(function() { 
    $ias.cancelSelection(); 
}); 
+0

如果您想重新打開對話框並再次選擇圖像區域,這是一個更好的答案。 @ Daniele的回答將完全刪除/銷燬你的元素中的插件,但是這隻會刪除視覺選擇框和背景。 – monty 2016-03-29 02:11:03

1

根據文檔:http://odyniec.net/projects/imgareaselect/usage.html

{remove:true}將實際上完全刪除imgAreaSelect-y-ness。如果你想要做的只是框和灰色區域(但允許用戶稍後拖動一個新框),你需要{hide:true}。

$('#image_area').imgAreaSelect({hide: true}); 
0
$('#image_area').imgAreaSelect({remove:true}); //For hiding the imagearea 
$('#image_area').imgAreaSelect({remove:false}); //For resetting the imagearea 

首先聲明隱藏imgareaselect和第二條語句幫助時進行模態下一次加載重裝作物功能。

我從模態返回到主窗口時使用了這兩個語句,以便下次加載裁剪功能時不存在問題。