2014-03-06 42 views
0

有誰知道一個很好的插件,可以幫助我完成以下操作: 我在網站上有一張圖片。一旦這張圖片被點擊,視頻播放器就會在屏幕的中心打開。該視頻是從YouTube上播放的。下面是該網站表示我想要什麼 - http://thumb.it/(見視頻畫面右側的watch our video標誌下插件在彈出窗口中播放視頻

回答

1

我幾年前做這個確切的事情,使用jQuery的fancybox插件(http://fancyapps.com/fancybox/)有。非常好可能是更好的彈出窗口/模式窗口的選擇,雖然我很滿意fancyBox,因爲它很容易處理。

FancyBox解決了點擊視頻縮略圖鏈接時顯示彈出窗口的問題。 ,你可以嵌入YouTube視頻(或HTML,或圖像,或任何東西 - 不只是視頻)。

直接在風扇cyBox文檔頁面,他們鏈接到這個JsFiddle:http://jsfiddle.net/M78zz/,它演示瞭如何從彈出鏈接啓動YouTube視頻。小提琴還演示瞭如何在第一個完成播放時使用YouTube API轉到下一個視頻。

這裏的的jsfiddle代碼:

HTML

<!-- This loads the YouTube IFrame Player API code --> 
<script src="http://www.youtube.com/player_api"></script> 

<a class="fancybox fancybox.iframe" href="http://www.youtube.com/embed/L9szn1QQfas?enablejsapi=1&wmode=opaque">Video #1</a> 

<br /> 

<a class="fancybox fancybox.iframe" href="http://www.youtube.com/embed/cYplvwBvGA4?enablejsapi=1&wmode=opaque">Video #2</a> 

的JavaScript

// Fires whenever a player has finished loading 
function onPlayerReady(event) { 
    event.target.playVideo(); 
} 

// Fires when the player's state changes. 
function onPlayerStateChange(event) { 
    // Go to the next video after the current one is finished playing 
    if (event.data === 0) { 
     $.fancybox.next(); 
    } 
} 

// The API will call this function when the page has finished downloading the JavaScript for the player API 
function onYouTubePlayerAPIReady() { 

    // Initialise the fancyBox after the DOM is loaded 
    $(document).ready(function() { 
     $(".fancybox") 
      .attr('rel', 'gallery') 
      .fancybox({ 
       openEffect : 'none', 
       closeEffect : 'none', 
       nextEffect : 'none', 
       prevEffect : 'none', 
       padding  : 0, 
       margin  : 50, 
       beforeShow : function() { 
        // Find the iframe ID 
        var id = $.fancybox.inner.find('iframe').attr('id'); 

        // Create video player object and add event listeners 
        var player = new YT.Player(id, { 
         events: { 
          'onReady': onPlayerReady, 
          'onStateChange': onPlayerStateChange 
         } 
        }); 
       } 
      }); 
    }); 

} 

CSS

.fancybox-nav { 
    width: 60px;  
} 

.fancybox-nav span { 
    visibility: visible; 
} 

.fancybox-next { 
    right: -60px; 
} 

.fancybox-prev { 
    left: -60px; 
} 
+0

謝謝,但我可以看到的fancybox是用於非商業用途只要。我需要一些開源的東西 –

+0

我也聽說過關於SimpleModal的好東西(http://www.ericmmartin.com/projects/simplemodal/),但實際上任何最新的模式插件都會有相同的想法 - pop您可以放置​​HTML或嵌入視頻。在此處使用YouTube視頻嵌入指南,比如將iframe放入模式(https://developers.google.com/youtube/player_parameters#Embedding_a_Player)中,它不應該是'無論您選擇哪種模式解決方案,都無法嵌入視頻。 – Sean

相關問題