2013-04-02 46 views
0

我有一個div元素,點擊它可以打開一個jQuery UI模式對話窗口。我想要做的是在模式對話框打開期間突出顯示div元素(意思是改變它的顏色),並在關閉對話框窗口時將其恢復到原始狀態。是否有可能這樣做?在jQuery UI模式對話框打開時執行動作

使用.css方法更改背景色並不像我想要的那樣工作。我的代碼:

HTML

<div id="help" class="hover">Help</div> 

<div id="helpdialog" class="helpbox"> 
<header id="helptitle">Help</header>  
<p id="helptext"> 
</p> 
    </div> 

JS

$('#help').on('click',function() { 
$('#help').css('background-color','#F0E68C'); 
$("#helpdialog").dialog({ 
height: 670, 
width: 570, 
modal: true, 
draggable: true, 
resizable: false, 
dialogClass: "helpbox", 
buttons: { Close: function() { $(this).dialog("close"); 
$('#help').css('background-color',''); } }, 
create: function(event, ui) 
{ 
$(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar").css("display","none");  
$(this).parents(".ui-dialog").css("padding", 0); 
$(this).parents(".ui-dialog").css("border", '1em solid #709CB4'); 
$(this).parents(".ui-dialog").css("border-radius", '0.6em');  
$(this).parents(".ui-dialog:first").find(".ui-dialog-content").css("padding",0); 
} 
}); 
}); 

回答

2

使用closeopen事件

$('#help').on('click', function() { 

    $("#helpdialog").dialog({ 
     height : 670, 
     width : 570, 
     modal : true, 
     draggable : true, 
     resizable : false, 
     dialogClass : "helpbox", 
     buttons : { 
      Close : function() { 
       $(this).dialog("close"); 
      } 
     }, 
     create : function(event, ui) { 
      $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar") 
        .css("display", "none"); 
      $(this).parents(".ui-dialog").css("padding", 0); 
      $(this).parents(".ui-dialog").css("border", '1em solid #709CB4'); 
      $(this).parents(".ui-dialog").css("border-radius", '0.6em'); 
      $(this).parents(".ui-dialog:first").find(".ui-dialog-content").css(
        "padding", 0); 
     }, 
     open : function(event, ui) { 
      $('#help').css('background-color', '#F0E68C'); 
     }, 
     close : function(event, ui) { 
      $('#help').css('background-color', ''); 
     } 
    }); 
}); 
+0

我試過了,沒有工作:/ – Ronophobia

+0

在CSS中,我的#help div的背景顏色設置爲#E2ECEB。我可以在關閉對話框時改變它的顏色,而不是在它打開的時候。 – Ronophobia

+0

似乎在這裏工作很好http://plnkr.co/edit/mpgIr5DGzv2RGYaJV7JW?p=preview –

0

取而代之的是

$('#help').css('background-color',''); 

設置一些色彩

$('#help').css('background-color','#aaa'); 
+0

沒有好,這不是problem.The顏色不會更改爲#F0E68C要麼同時對話框打開。它只是保持其默認顏色。頁面的其餘部分按預期變暗,但我希望在屏幕上打開對話框時保持#help div的顏色。 – Ronophobia