Problem leaving a fixed video in the background of a Section

Asked

Viewed 309 times

0

ex:

( Section background is fixed, but video is not )

Could someone help me get the video fixed equal to bg from Ction?

code:

@import url('https://fonts.googleapis.com/css?family=Paytone+One');
*{
	margin: 0;
	padding: 0;
	font-family: helvetica;
}



header{
	z-index: 5;
	position: fixed;
	width: 100%;
	height: 70px;
	background-color: #fff;
	-webkit-transition: background-color .5s;
}

nav{
	display: table;
	margin: auto;
	margin-top: 15px;
	height: 40px;
	-webkit-transition: margin-left .5s;
}

ul{
	margin-right: 850px;
	display: block;
	float: right;
	list-style: none;
}

ul li{
	float: left;
	margin: 10px;

}

ul a{
	color: #000;
	text-decoration: none;
	-webkit-transition: color .1s;
}

body{
    margin: 0;
    padding: 0;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-weight: 300;
    background-color: #3F51B5;
    color: #fff;
}
.center{
    text-align: center;
}

.parallax-target{
    min-height: 650px;
    background: transparent center fixed;

}

.parallax-targett{
    min-height: 600px;
    background: transparent;
}
.parallax-targettt{
    min-height: 600px;

}

.middle{
    min-height: 400px;
}
.slide{
	background-image: url(../img/2853636-firewatch-wallpapers.png);
    background-repeat: no-repeat; 
	background-attachment: fixed;
	background-size: cover;
	width: 100%;
	height: 700px;
}
.content{

}
		<section class="slide">
			<div class="content">
<p style="text-align: center;"> <iframe src="http://www.youtube.com/embed/QN_FdiMItvA?autoplay=1&amp;modestbranding=1&amp;nologo=1&amp;rel=0&amp;showinfo=0&amp;theme=light&amp;wmode=opaque&amp;controls=0" width="690" height="400" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
				</div>
</section>
	
	

1 answer

1


Remove the tag <p> which does not serve to centralise such elements.

You can make video responsive with the maximum width set in the attribute width of iframe. Take the proportion of width and height and insert a jQuery that will center and make your video responsive and centered on the page:

Add the CSS for iframe that will fix and center it:

iframe{
   position: fixed;
   -webkit-transform: translate(-50%, -50%);
   -moz-transform: translate(-50%, -50%);
   transform: translate(-50%, -50%);
   top: 50%;
   left: 50%;
}

Iframe HTML:

<iframe src="http://www.youtube.com/embed/sVxBaRYnjgE?autoplay=1&amp;modestbranding=1&amp;nologo=1&amp;rel=0&amp;showinfo=0&amp;theme=light&amp;wmode=opaque&amp;controls=0" width="690" height="400" frameborder="0" allowfullscreen="allowfullscreen"></iframe>

jQuery:

$(window).on("load resize", function(e){
   var vid = $("iframe");

   if(e.type == "load"){
      var vid_w_tag = vid.attr("width");
      var vid_h_tag = vid.attr("height");
      proporcao = vid_w_tag/vid_h_tag;
      vid.attr("width","100%")
      .css('max-width', vid_w_tag+'px');
   }

   var vid_w = vid.width();
   vid.attr('height',vid_w/proporcao);
});
  • Opa mano só estou com um problema agora ele está acompanhando o scroll até o fim da page, but like me I wanted the video to be fixed in this background: https://imgur.com/a/AynPM, but it’s like this : https://imgur.com/a/Y7bPq

  • @Felipe Tries changing position: Fixed by position: Absolute

  • The Archive worked, but can you take away just one more question? qnd I add the background-Attachment: Fixed; in the background the video doesn’t stay fixed there’s no way to fix it? Or the script I imported wrong?

  • @Felipe man, the background has nothing to do with the video. One thing different from the other

  • Like so bro I put the iframe inside a Section and this Section I called a background img, bg no repeat, bg size, bg Attachment Fixed and type because of Attachment Fixed the video not fixed and I was wanting to do

  • an effect next to Parallax

  • what I am trying to do is equal to the video and the video bg of this page here: https://elojobbrasil.com.br/.

  • @Felipe has no way of understanding this. The background of Section is one thing, what’s inside Section is the thing. Background is nothing but an image in the background, does not disturb anything in the elements.

  • @Felipe But this is more complex thing. It involves many things.

  • 'Cause I’m also not getting it because the video moves qnd I rip the scroll when I use Attachment in the section, I’ll send you a jsfiddle only with the css and html of this part to see if I missed something.

  • https://jsfiddle.net/akpuavkr/ @dvd I know, but I was just trying to do that part of their video there, if you could take a look and see if there’s anything wrong with the code.

  • @Felipe No Jsfiddel appears nothing, only the codes. Things like this are complicated, have to be part by part, go testing

  • ah did not know it was so complex so I will leave them two fixed even :( .

  • But obrgd for taking away my doubt bro!

  • @Felipe Fazer efeito paralax eh dificil, tem que saber muito de CSS e Javascript

  • I managed to fzr something really cool with the plugin and ta attending well until, the only thing q caught was in this part ai q i wanted to leave a fixed video + bg .

Show 11 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.