2011-02-28 56 views
7

我一直試圖讓這段代碼工作。我有一個隱藏的div,使用object/embed方法顯示Flash視頻。在Fancybox中顯示隱藏的div使用JQuery不工作

這是我使用的js代碼。

jQuery(document).ready(function(){ 

    jQuery("a[id^='scrshot_']").fancybox(  
    { 
    'autoDimensions' : false, 
    'width'     : 640, 
    'height'    : 360  
    }); 
    return false;}); 

我用這個方法我在這個網站http://www.jdmweb.com/resources/fancy_videos,並很容易實現發現。我使用動態創建的ID標籤。但由於某些原因fancybox將打開,但div內隱藏。當我使用螢火蟲查看它時,它會顯示內部的閃存對象,但它仍然具有display:none屬性。你如何得到它顯示該div內的內容而不是整個div?如果div顯示並使用該鏈接,fancybox就會打開播放器。很明顯,這將無法正常工作,因爲我不希望視頻顯示,直到它在fancybox啓動。

我的html代碼示例。

<a class='scrshot' id='scrshot_1' href='#showvid_1'>Click Here</a> 
<div class='showvid' id='showvid_1'>my embedded code here</div> 

回答

20

而不是隱藏div,使其可見,但將其包裹在另一個隱藏的div內。

(我不知道爲什麼的fancybox不切換的知名度,相當惱人。)

+0

正確答案,應該接受。優雅而簡單 – styler1972 2012-06-06 20:21:19

1

嘗試添加這對您的jQuery(document).ready(function(){

jQuery('.scrshot').live('click',function(){ 
    jQuery('.showvid').hide();     //hide any that might be open 
    jQuery(jQuery(this).attr('href')).show(); //show the div we clicked for 
});