相关疑难解决方法(0)

全屏背景视频并保持居中

我正在尝试创建一个网站,我在其中播放一些HTML5背景视频.这一切都很完美,它按照我想要的方式工作.但我也希望将图像保持在屏幕中心,即使用户调整浏览器大小.

<video id="video" src="video/video.mov" type="video/mov" autoplay loop></video>
Run Code Online (Sandbox Code Playgroud)

我得到了这个与一些jQuery,但想知道是否有一个CSS解决方案.

function resizeHandler() {
        // scale the video
        var documentHeight = $(document).height();
        var documentWidth = $(document).width();
        var ratio = $('#video').width() / $('#video').height();

        if((documentWidth / documentHeight) < ratio) {
            $('#video').css({
                'width': 'auto',
                'height': '100%',
                'left': '0px',
                'right': '0px',
                'top': '0px',
                'bottom': '0px'
            })

            var marginRight = $('#video').width() - $(document).width();
            $('#video').css('left', -marginRight);
        } else {
            $('#video').css({
                'width': '100%',
                'height': 'auto',
                'left': '0px',
                'right': '0px',
                'top': '0px',
                'bottom': '0px'
            })

            var marginTop = $('#video').height() - $(document).height(); …
Run Code Online (Sandbox Code Playgroud)

javascript css video jquery html5

10
推荐指数
2
解决办法
7681
查看次数

标签 统计

css ×1

html5 ×1

javascript ×1

jquery ×1

video ×1