admin管理员组

文章数量:1400161

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.

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.

Share Improve this question edited Apr 27, 2019 at 9:56 Rachel Gallen 28.6k22 gold badges75 silver badges86 bronze badges asked Jul 24, 2015 at 14:48 Yavuz SelimYavuz Selim 5462 gold badges7 silver badges22 bronze badges 2
  • Can we have your code in fiddle. – Steevan Commented Jul 24, 2015 at 14:52
  • Please post a demo in jsFiddle. I've had troubles as you have described, but it's better if I can see what you've already done so I don't have to "reinvent the wheel" – zer00ne Commented Jul 24, 2015 at 14:53
Add a ment  | 

3 Answers 3

Reset to default 3

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.']"),

    // 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();

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/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./2710053.mp4" type="video/mp4"/>
                <source src="http://view.vzaar./2710053.ogg" type="video/ogg"/>
                <source src="http://view.vzaar./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
}

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.

本文标签: javascriptPut a text on fullscreen video (HTML5)Stack Overflow