admin管理员组文章数量:1278983
I have initialized a youtube video with youtube apis in a div with certain dimensions. Is it possible to display the video as it would be an image set as background sized cover of a div? I mean without any black spaces.
Here below you can find the actual result and the code I used.
Code:
var player123;
if(jQuery('#player123')){
bindVideo();
}
function bindVideo(){
var playerHeight = "500px";
if(jQuery(window).width() < 1023){
playerHeight = "100%";
}else{
playerHeight = "400px";
}
jQuery(window).resize(function(){
if(jQuery(window).width() < 1023){
playerHeight = "100%";
}else{
playerHeight = "400px";
}
});
player123 = new YT.Player('player123', {
height: playerHeight,
width: '100%',
videoId: 'video-id-here',
events: {
'onReady': onPlayerReady(event),
'onStateChange': onPlayerStateChange
},
playerVars:{
rel:0,
loop:1,
showinfo:0,
controls:0,
disablekb:1
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
//event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if(event.data == "2"){
pauseVideo();
}else if(event.data == "0"){
stopVideo();
}
}
function stopVideo() {
jQuery("#player-overlay").show();
player123.stopVideo();
}
function PlayVideo2(){
jQuery("#player-overlay").hide();
player123.playVideo();
}
function pauseVideo(){
jQuery("#player-overlay").show();
player123.pauseVideo();
}
Is there any parameter to set to remove them ?
I have initialized a youtube video with youtube apis in a div with certain dimensions. Is it possible to display the video as it would be an image set as background sized cover of a div? I mean without any black spaces.
Here below you can find the actual result and the code I used.
Code:
var player123;
if(jQuery('#player123')){
bindVideo();
}
function bindVideo(){
var playerHeight = "500px";
if(jQuery(window).width() < 1023){
playerHeight = "100%";
}else{
playerHeight = "400px";
}
jQuery(window).resize(function(){
if(jQuery(window).width() < 1023){
playerHeight = "100%";
}else{
playerHeight = "400px";
}
});
player123 = new YT.Player('player123', {
height: playerHeight,
width: '100%',
videoId: 'video-id-here',
events: {
'onReady': onPlayerReady(event),
'onStateChange': onPlayerStateChange
},
playerVars:{
rel:0,
loop:1,
showinfo:0,
controls:0,
disablekb:1
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
//event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if(event.data == "2"){
pauseVideo();
}else if(event.data == "0"){
stopVideo();
}
}
function stopVideo() {
jQuery("#player-overlay").show();
player123.stopVideo();
}
function PlayVideo2(){
jQuery("#player-overlay").hide();
player123.playVideo();
}
function pauseVideo(){
jQuery("#player-overlay").show();
player123.pauseVideo();
}
Is there any parameter to set to remove them ?
Share Improve this question asked Oct 9, 2017 at 17:21 Pierpaolo ErcoliPierpaolo Ercoli 1,0642 gold badges13 silver badges32 bronze badges1 Answer
Reset to default 11You may refer with this thread. This code will give you a video that fills the container that it is in and will automatically scale the height too.
.video-wrapper {position: relative; padding-bottom: 56.25%; /* 16:9 */ padding-top: 25px;}
.video-wrapper iframe {position: absolute; top: 0; left: 0; width: 100%; height: 100%;}
<div class="video-wrapper">
<iframe src="http://www.youtube./embed/AddHereVideoId?autoplay=1&html5=1" frameborder="0" allowfullscreen></iframe>
</div>
Additional references:
- Fluid Width Video
- Shrink a YouTube video to responsive width
本文标签: javascriptHow to fit Youtube video size with div containerStack Overflow
版权声明:本文标题:javascript - How to fit Youtube video size with div container - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741209916a2358905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论