1
YouTubeビデオを埋め込んだjQueryモバイルポップアップ(または任意のタイプのjavascriptモーダル)を作成してカスタムコントロールが可能です。jQueryモバイルYouTubeカスタムコントロールを使用したポップアップ
ここには、基本的な「再生」ボタンが付いたJSFiddle demoがあり、私の問題を示すのに役立ちます。
基本的に、私はHTML内のiframeコードを持っている:
<iframe id="iframe-video" width="400" height="300" src="http://www.youtube.com/embed/a0gact_tf_0" frameborder="0" allowfullscreen></iframe>
そして、ビデオがロードされたときに、私はこれを行う:動画の読み込み
$(document).on("pagecreate", function() {
// bind click events
$(document).on('click', '#play', function() {
playVideo();
return false;
});
$(".ui-popup iframe")
.attr("width", 0)
.attr("height", "auto");
$("#popupVideo").on({
popupbeforeposition: function() {
initYoutubePlayer();
// call our custom function scale() to get the width and height
var size = scale(497, 298, 15, 1),
w = size.width,
h = size.height;
$("#popupVideo iframe")
.attr("width", w)
.attr("height", h);
},
popupafterclose: function() {
$("#popupVideo").html("<span></span>");
$("#popupVideo iframe")
.attr("width", 0)
.attr("height", 0);
},
});
});
function initYoutubePlayer() {
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
alert('onYouTubeIframeAPIReady');
player = new YT.Player('iframe-video', {
events: {
'onReady': onPlayerReady,
}
});
};
function onPlayerReady(event) {
alert('ready');
};
alert('initialized');
}
function playVideo() {
alert('playVideo...');
//player.playVideo();
}
が正常に動作しますが、私はできませんがYT.Playerをインスタンス化できるところでYouTube iFrame APIが動作するようにしてください。言い換えれば、 'onYouTubeIframeAPIReady'は起動しません。
私はこのJSFiddleコードのすべての種類の並べ替えを試みましたが、明らかに何かが不足しているように感じます。
カスタムYouTubeコントロールをjQuery Mobile Popupまたはjavascriptモーダルで使用することはできますか?速かった
うわー、。ありがとうございました! – kanso
@kanso喜んで助けました。フィドルは完璧に動作します。なんらかの理由でスニペットが正しく実行されませんでした。 – Iceman