Autostart embedded Youtube video with Fancybox

I have a linked image on my page that, when clicked, loads the Fancybox modal block . He does it successfully, but I want the video to be autorun . If I set the YouTube URL autoplay=1, the hidden DIV will play in the background when the page loads.

// Here is the linked image
<a id="inline" href="#video"><img src="someimage.jpg" alt="Description" /></a>

// Here is the hidden DIV
<div style="display:none">
  <div id="video">
    <iframe title="YouTube video player" width="640" height="390" src="###YOUTUBE LINK###rel=0&amp;hd=1&amp;autoplay=0" frameborder="0"></iframe>
  </div>
</div>

// Here is the script
<script type="text/javascript">
  $("a#inline").fancybox({
    'hideOnContentClick': true,
  });
</script>

I suppose I need to do some kind of Bind () event and replace the string to change autoplay=0to autoplay=1, but I tried several options without any success

Any thoughts please?

+5
source share
1 answer

href URL- YouTube, , "autoplay=1" ( URL). <div> 4 " " FancyBox, :

$("#tip4").click(function() {
    $.fancybox({
            'padding'       : 0,
            'autoScale'     : false,
            'transitionIn'  : 'none',
            'transitionOut' : 'none',
            'title'         : this.title,
            'width'     : 680,
            'height'        : 495,
            'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'          : 'swf',
            'swf'           : {
                 'wmode'        : 'transparent',
                'allowfullscreen'   : 'true'
            }
        });

    return false;
});

, , JS .

+8

All Articles