Yavuz Selim
Yavuz Selim

Reputation: 546

Put a text on fullscreen video (HTML5)

I want to put text on fullscreen video at HTML.

I could make it non fullscreen but it is not working on fullscreen.

Is there any way to do it?

I use position:absoulute for text and position:relative/fixed/none for video.

Also I don't know if it works but I called .requestFullscreen(); function for browser unhappily I cannot resize video.

If .requestFullscreen(); is works. I need to resize video.

width and height of video tags is changing but video is not changing.

Upvotes: 6

Views: 4921

Answers (3)

Tony Ray Tansley
Tony Ray Tansley

Reputation: 669

Had this problem before but it's pretty simple code in the end (it still took me ages to figure out and get the right balance) https://jsfiddle.net/tonytansley/xwuuttdt/

Just a little absolute positioning and using percentages as your widths heights and paddings.

<body>
    <div id="outer">
        <div id="home-top-video">
            <video autoplay loop width="100%">
                <source src="http://view.vzaar.com/2710053.mp4" type="video/mp4"/>
                <source src="http://view.vzaar.com/2710053.ogg" type="video/ogg"/>
                <source src="http://view.vzaar.com/2710053.webm" type="video/webm"/>
            Your browser does not support the video tag. We suggest you upgrade your browser.
            </video>
            <div id="home-text">
                    <h1>text</h1>
                    <h3>subtext</h3>
             </div>
        </div>
    </div>
</body>

css

#outer{
    width:100%;
    display:block;
    text-align:center;
    position:relative;
    overflow: hidden;
    height:10000px;
    min-height:100%;
}
#home-top-video{
    left:0%;
    top:0%;
    height:100%;
    width:100%;
    overflow: hidden;
    position: absolute;
    z-index: -1;
}
#home-text{
    left:0%;
    top:0;
    height:100%;
    width:100%;
    padding-top:10%;
    overflow: hidden;
    position: absolute;
    z-index: 0;
    color:white
}

Upvotes: 2

Rachel Gallen
Rachel Gallen

Reputation: 28563

You can embed responsively with Youtube and vimeo with iframes, and with Viddler and Blip.tv with object embed. There is an article that explains it here and code is available on github

Sample code for Youtube (using jquery):

// Find all YouTube videos
var $allVideos = $("iframe[src^='//www.youtube.com']"),

    // The element that is fluid width
    $fluidEl = $("body");

// Figure out and save aspect ratio for each video
$allVideos.each(function() {

  $(this)
    .data('aspectRatio', this.height / this.width)

    // and remove the hard coded width/height
    .removeAttr('height')
    .removeAttr('width');

});

// When the window is resized
$(window).resize(function() {

  var newWidth = $fluidEl.width();

  // Resize all videos according to their own aspect ratio
  $allVideos.each(function() {

    var $el = $(this);
    $el
      .width(newWidth)
      .height(newWidth * $el.data('aspectRatio'));

  });

// Kick off one resize to fix all videos on page load
}).resize();

Upvotes: 3

codestr
codestr

Reputation: 201

You can acheive this in a couple different ways. I believe the easiest would be to create a div that's 100% width, embed the video responsively inside the div, and then absolutely position the text in the center of the div.

Upvotes: 0

Related Questions