2011-01-14 65 views
2

隱藏某個DIV時觸發某個功能的最佳方法是什麼?隱藏某個元素時的jQuery觸發功能

我想在元素被隱藏時從頁面中銷燬一些Flash對象,並在顯示元素時重新創建它們。

例如

<div id="flashContainer> // flash object </div> 

$("#flashContainer).hide(); //trigger function that destroys the flash object 
$("#flashContainer).show(); //trigger function that creates the flash object 

背景:

我想這樣做的原因是,我有一個很長的網頁,有一些導航是「臺階throught」申報單,如果他們的網頁。在IE中,所有這些隱藏的div加載了閃光燈並開始下載視頻,在這個過程中

回答

1

jQuery的provides an override到展()和隱藏()方法,可以讓你傳遞一個一旦動畫發射的回調函數完成

.show(持續時間,[回調])

您可以像這樣使用

$('#flashContainer').hide('slow', function(e) { 
    //put your code here to remove your flash 
    $('#flashId').remove(); //something like this maybe 
    alert('hidden'); 
}); 

$('#flashContainer').show('slow', function(e) { 
    //add your flash here 
}); 

然而在show()的情況下,在你的Flash對象被加載,所以你可能需要調用show()

$('#flashcontainer').append('<object><!-- your flash html here --></object>'); 
$('#flashcontainer').show(); 
1
$("#flashContainer:hidden").show(); 

從jQuery的官方頁面兩者佔用內存和帶寬,這是否幫助?

你能更具體嗎?

+0

這將只顯示容器我之前已經創建您的閃光燈flashcontainer將顯示隱藏,我需要觸發一個事件時,某些類型(由類定義)的DIV顯示/隱藏 – Keeno 2011-01-14 15:13:27

+0

然後你需要的是一個IF語句,和/或一個setInterval函數來檢查DIV是否:隱藏 – benhowdle89 2011-01-14 15:16:55

0

最好是顯示和隱藏flash對象而不是裝箱和銷燬。

喜歡的東西

$("#flashContainer).hide("slow", function(){ 
    $("#yourflashobjid").hide(); 
}); 

$("#flashContainer).show("slow", function(){ 
    $("#yourflashobjid").show(); 
});