我想創建一個網站,我有一些HTML5背景視頻播放。 這一切都是完美的工作,它只是我想要的方式。 但我也想保持中心的屏幕上的圖像,甚至當用戶改變瀏覽器。全屏背景視頻,並保持居中
<video id="video" src="video/video.mov" type="video/mov" autoplay loop></video>
我得到這個與一些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();
$('#video').css('top', -marginTop);
}
}
這是我寫的jQuery,用於拉伸圖像以適應屏幕,並保持圖像的中心排序。 不知道這是可能的CSS,但如果有人知道如何,這可能是好的。
是存在的,爲什麼你關心的CSS實現這一功能的原因嗎?如果它起作用,它就會起作用。 – maxedison
不是,我只是好奇是否可能在CSS中,只是好奇。 –
這是否以任何瀏覽器大小爲中心? – Jorre