Created
March 6, 2013 04:01
-
-
Save run26kimo/5096593 to your computer and use it in GitHub Desktop.
iframe 嵌入 Youtube 自動播放 , 靜音
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<iframe class="youtube-player" id="player" type="text/html" src="http://www.youtube.com/embed/EnErifh93hM?autoplay=1" height="600px" width="400px"></iframe> | |
<!-- 1. The <div> tag will contain the <iframe> (and video player) --> | |
<div id="player"></div> | |
<script> // 2. This code loads the IFrame Player API code asynchronously. | |
var tag = document.createElement('script'); | |
tag.src = "http://www.youtube.com/player_api"; | |
var firstScriptTag = document.getElementsByTagName('script')[0]; | |
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
// 3. This function creates an <iframe> (and YouTube player) | |
// after the API code downloads. | |
var player; | |
function onYouTubePlayerAPIReady() { | |
player = new YT.Player('player', { | |
playerVars: { 'autoplay': 1, 'controls': 1,'autohide':1,'wmode':'opaque' }, | |
videoId: 'JW5meKfy3fY', | |
events: { | |
'onReady': onPlayerReady} | |
}); | |
} | |
// 4. The API will call this function when the video player is ready. | |
function onPlayerReady(event) { | |
event.target.mute(); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment