2013-03-11 19 views
2

我試圖創建一個畫廊組,混合圖像和視頻與視頻使用JWPlayer6。Fancybox2與圖像和視頻在同一組使用JWPlayer 6

我每個人都作爲獨立的團隊工作,但我不能鍛鍊如何將兩者結合起來。

<!-- FancyBox to display images --> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $(".fancybox").fancybox({ 
     helpers : { 
     title : { type : 'inside' } 
     }, // helpers 
     beforeLoad: function(){ 
     } 
     }); 
    }); 

<!-- FancyBox to display videos --> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    $(".fancybox-video").fancybox({ 
     content: '<div id="video_container" style="">Loading video...</div><br>', 
     autoSize: true, 
     helpers : { 
      title : { type : 'inside' } 
      }, // helpers 
     beforeLoad: function(){ 
      this.title = $(this.element).attr('caption'); 
      }, 
     afterShow: function(){ 
      jwplayer("video_container").setup({ 
      flashplayer: "/static/js/libs/jwplayerjwplayer.flash.swf", 
      file: this.href, 
      autostart: 'true' 
      }); // jwplayer setup 
      } // afterShow 
     }); // fancybox 
}); // on 
</script> 
+0

你有沒有嘗試將兩者以及兩者分開的例子? – emaxsaun 2013-03-11 16:52:38

+0

它們都需要使用相同的選擇器並使用不同的'data-fancybox-type'屬性 – JFK 2013-03-11 17:58:19

+0

...另外你還有一個額外的'return false; //防止默認值'無所作爲...複製/粘貼的缺點之一;) – JFK 2013-03-11 18:00:18

回答

2

好吧,我不知道這是肯尼迪是在暗示,但這似乎工作,但必須有做更有效的方式:

<style type="text/css"> 
.fancybox-nav { 
height: 80%; 
} 
</style> 

<script type="text/javascript"> 
    $(document).ready(function() { 
    $(".fancybox").fancybox({ 
     autoSize: true, 
     helpers : { 
      title : { type : 'inside' } 
      }, // helpers 
     beforeLoad: function(){ 
      if($(this.element).attr('containertype')=='video'){ 
      this.content = '<div id="video_container" style="">Loading the player ... </div><br>'; 
      }; 
      }, 
     afterShow: function(){ 
      if($(this.element).attr('containertype')=='video'){ 
      jwplayer("video_container").setup({ 
      flashplayer: "jwplayer.flash.swf", 
      file: this.href, 
      autostart: 'true' 
      }); // jwplayer setup 
      }; 
     }// afterShow 
    }); // fancybox 
}); // on 
</script> 

和HTML:

<a class="fancybox" rel="group" title="Video 1" data-fancybox-type="anything" containertype="video" href="1.flv"><img src="1.png"/></a> 
<a class="fancybox" rel="group" title="Image 2" href="2.png"><img src="2.png"/></a> 
+0

根據文檔,data-fancybox-type =「anything」應該是'image','inline','ajax','iframe','swf'和'html'...我想你的大小寫應該是'html'(圖像通常是自動檢測的,除非它們沒有圖像擴展名,所以在這種情況下,您必須指定'data-fancybox-type =「image」') – JFK 2013-03-12 00:17:57

+0

如果您指定'data- fancybox-類型'然後我想你可以像if(this.type =「html」)'而不是'if($(this.element).attr('containertype')=='video')'' – JFK 2013-03-12 00:19:53

+0

+ 1:我想你可以接受你自己的回答http://meta.stackexchange.com/a/5235 – JFK 2013-03-12 00:20:29