Welcome to the Instapage Support Center

|

Video Background for Page Sections

Using the following custom coded solution you can add any Youtube video as a video background for any of your sections.

The information you will need to set this up on your landing page is the Youtube video ID and the page section on which you would want to have the video background.

How to get the Youtube video ID

youtubeVideoID2.png

The following code needs to be added under Settings - JavaScript, Header:

<script>
jQuery(document).ready(function(){ 
  // Add below the Youtube video ID
  var videoID = "xxxxx";
  // Add below the number of your section on which you would want to have the video background
  var pageSection = 1;
  
  var $youtubevid ='<div class="video-background"><div class="video-foreground" id="video-foreground"><iframe src="https://www.youtube.com/embed/'+ videoID +'?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&playlist='+ videoID +'" frameborder="0" allowfullscreen></iframe></div></div>';  
  pageSection = pageSection + 1;
  var $sectionID = $('.page-block:nth-of-type('+ pageSection +')').attr('id');
  $sectionID = '#'+$sectionID;
  $( $sectionID ).append($youtubevid);
  $( $sectionID ).css({"overflow":"hidden"});
  $( $sectionID + ' .color-overlay' ).css({"z-index":"1"});
  
$(function(){ $('.video-foreground').css({ width: $(window).innerWidth() + 'px' }); var dw = 1264; $(window).resize(function(){ var cw = $(window).innerWidth(); var xw = dw - cw; $('.video-foreground').css({ width: cw + xw + 'px'}); }); }); }); </script>

Now you will need to add your own Youtube video ID in the videoID parameter

videoID.png

And the page section on which you want to have the video background

pagesection.png

In the example above, we are adding the video background to the first section of the page from the top. If you want to add it to the second section you will need to replace 1 with 2, and so on if you want to add it to any other section.

The next step is to add the CSS styling for this feature, the code below needs to be added under Settings - HTML/CSS - Header

<style>
@media only screen and (max-width: 640px){
.video-background{
display: none;
}
} @media only screen and (min-width: 640px){ .video-background { position: absolute; top: 0; right: 0; bottom: 0; left: 0; } .video-foreground, .video-background iframe { position: absolute; pointer-events: none; top: 50%; left: 50%; min-width: 100%; min-height: 100%; width: auto; height: auto; transform: translateX(-50%) translateY(-50%); background-size: cover; transition: 1s opacity; height: calc(100vh + 150px); width: 100%; } } </style>

 

Live Example

Note: The video background will not be available on mobile devices or mobile screen sizes.

Have more questions? Submit a request
Was this article helpful?
3 out of 4 found this helpful

Need Further Help?

Tell us what you need and we will be happy to assist you.

Our team of expert support staff and our community can answer your questions. Submit a ticket, reach out on live chat or call us now!