What is the most efficient way to load YouTube videos through jQuery on a user click?

前端 未结 3 905
半阙折子戏
半阙折子戏 2021-02-06 10:04

I\'m trying to determine what is the most efficient way to load videos into a on a user click using jQuery.

To give more context behind this, I\'ll have about 30 clips

相关标签:
3条回答
  • 2021-02-06 10:34

    You could also try to have jQuery change the iframe src property.

    You might run into trouble with the iframe in Internet Explorer. This page describes the problem: http://osdir.com/ml/youtube-api-gdata/2011-03/msg00369.html
    If you can put in conditional scripting that will use the flash embed instead of the iframe if it is in Internet Explorer, that might be the best way to do it.

    0 讨论(0)
  • 2021-02-06 10:35

    you can add the URL to your Href and get it in the call Something Like:

    In your HTML:

    <a href="bMvRdr-mUOU" id="johnk" class="vid_trigger">
    

    Now in your JQuery:

    $('.vid_trigger').click( function(e){
    e.preventDefault();
    var URL = $(this).attr('href');
    var htm = '<iframe width="425" height="349" src="http://www.youtube.com/embed/' + URL + '?rel=0" frameborder="0" allowfullscreen ></iframe>';
    
        $('#video_container').html(htm);
    
    return false;
    });
    
    0 讨论(0)
  • 2021-02-06 10:42

    Use Colorbox

    A light-weight, customizable lightbox plugin for jQuery 1.3, 1.4, and 1.5
    Sample

    0 讨论(0)
提交回复
热议问题