2013-05-05 334 views
0

我嵌入YouTube視頻在我的網站是這樣的:嵌入YouTube視頻

<iframe width="320" height="180" src="http://www.youtube.com/embed/12345678" 
    style="border: none" allowfullscreen id="myVideo"></iframe> 

這個iframe中的href下載一本是2.7 KB

那下載這些:

所以即使用戶不看視頻的是,他幾乎下載356 KB的數據。在我的網站上顯示Youtube視頻的更好方式是什麼,但在用戶想要觀看視頻時加載這些數據?

+0

只要你不借助iframe overpopulate您的網頁,我想說356 KB的數據並不是真正需要擔心的事情。 – Juampi 2013-05-05 12:10:15

+1

是的,但這會降低網頁的移動性能。 – trante 2013-05-05 12:13:25

+0

這就是您爲嵌入YouTube視頻付出的代價。您可以嘗試使用重定向到實際視頻的縮略圖。 – Juampi 2013-05-05 12:17:16

回答

2

您可以使用縮略圖,當用戶點擊縮略圖只加載玩家

你可以看到怎麼辦的主題瀏覽器例如,這使用AngularJS一個例子

應用:

https://yt-topic-explorer.googlecode.com/git/dist/index.html

查看:

https://code.google.com/p/yt-topic-explorer/source/browse/app/views/main.html

代碼片段:

<div class="player-container"> 
     <img ng-click="videoClicked($event.target, videoResult.id)" ng-src="{{videoResult.thumbnailUrl}}" class="thumbnail-image"> 
     <div class="title"><a ng-href="{{videoResult.href}}" target="_blank">{{videoResult.title}}</a></div> 
</div> 

控制器:

https://code.google.com/p/yt-topic-explorer/source/browse/app/scripts/controllers/main.js

代碼片段:

function playVideo(container, videoId) { 
    var width = container.offsetWidth; 
    var height = container.offsetHeight; 

    new YT.Player(container, { 
     videoId: videoId, 
     width: width, 
     height: height, 
     playerVars: { 
     autoplay: 1, 
     controls: 2, 
     modestbranding: 1, 
     rel: 0, 
     showInfo: 0 
     } 
    }); 
+0

謝謝。我實現了它。 – trante 2013-05-14 05:54:21