pupunzi / jquery.mb.YTPlayer

use a custom yutube player for a video as background on jQuery framework
https://pupunzi.com/mb.components/mb.YTPlayer/demo/demo.html
1.32k stars 429 forks source link

How do I go about passing a specific height and width to an embedded youtube video? #438

Closed CyberiaResurrection closed 5 years ago

CyberiaResurrection commented 5 years ago

I'm using version 3.2.9 to try to embed a youtube video as a background for a specific div on the page. That's working, but distorts the size of the containing div - how can I pass a specific size (whether in pixels, %, vh/vw, etc) into the dataProperty to avoid that distortion?

pupunzi commented 5 years ago

Hi, How are you initializing the YTPlayer to run inside the DIV? The right way that will not distort the original containment div is:

<!-- The div where the video will play as background -->
<div id="myVideoBanner" class="myVideoBanner"></div>

<!--  The div to declare the player -->
<div id="P1" class="player" 
     data-property="{ videoURL:'http://youtu.be/xxxxxx', containment:'#myVideoBanner', startAt:0, mute:false, autoPlay:true, loop:true,opacity:1}">
</div>

And then via javascript:

    jQuery(function(){
      jQuery("#P1").YTPlayer();
    });

This will not modify the DIV.

While if you use "self" as containment declaring the background video on the same DIV the player will be managed not as background but as a chromeless player forcing the aspect ratio of the container to fit the video size.

CyberiaResurrection commented 5 years ago

Thanks - that worked.