2016-12-11 7 views
0

私はYouTubeの予告編に遅延ロードを使用していますが、モバイルデバイスでは動作しないことに気付きました。埋め込みオブジェクトにFlashを変更する

この機能ベッドをオブジェクトに埋め込むように変更できますか?

$('a.youtube-video').click(function(e) { 
    e.preventDefault(); 
    var videoId = $(this).attr('data-video'); 
    var params = { allowScriptAccess: "always", allowFullScreen: "true" }; 
    var atts = { id: 'player_'+videoId }; 
    $(this).hide(); 
    swfobject.embedSWF(
     "http://www.youtube.com/v/"+videoId+"?enablejsapi=1&playerapiid=ytplayer&version=3", 
     'placeholder_'+videoId, "100%", "315", "8", null, null, params, atts); 

}); 

すべてのヘルプは素晴らしいことだ...

これは完全なコードです:

<script>$(document).ready(function() { 
$('a.youtube-video').each(function() { 
    var videoId = $(this).attr('data-video'); 
    var videoThumbnail = "http://img.youtube.com/vi/" + videoId + "/0.jpg"; 
    var videoBackground = $('<span class="youtube-thumbnail"></span>'); 
    videoBackground.css({ 
     background:"#fff url('"+videoThumbnail+"') no-repeat",   
backgroundSize: 'cover' 

    }); 

    // also set the parent container size to prevent flicker 
    $(this).add($(this).parent()).css({ 
     height:315, 
     width:"100%", 
     position:"relative", 
     display:"block", 
     textAlign:"center", 
     color:"#fff", 
     fontSize:26 


    }); 
    $(this).text('Click to load video'); 
    $(this).append(videoBackground); 
}); 

$('a.youtube-video').click(function(e) { 
    e.preventDefault(); 
    var videoId = $(this).attr('data-video'); 
    var params = { allowScriptAccess: "always", allowFullScreen: "true" }; 
    var atts = { id: 'player_'+videoId }; 
    $(this).hide(); 
    swfobject.embedSWF(
     "http://www.youtube.com/v/"+videoId+"?enablejsapi=1&playerapiid=ytplayer&version=3", 
     'placeholder_'+videoId, "100%", "315", "8", null, null, params, atts); 

}); 

});

答えて

2
$('a.youtube-video').click(function(e) { 
    e.preventDefault(); 
    var videoId = $(this).attr('data-video'); 
    $("#player_" + videoId).html('<iframe width="100%" height="315" src="https://www.youtube.com/embed/' + videoId + '" frameborder="0" allowfullscreen></iframe>'); 
}); 
+0

私はうまくいくはずですが、何もしません。既に動画が必要な場所にiframeが必要ですか? –

+0

いいえ、対応するIDを持つ空のdivを追加するか、即座に作成してください。 – Vagharsh

+0

なぜこの文句を言わない仕事かわからない... これはdiv要素

「のためのコードであり、 –

関連する問題