내 요소의 가로 세로 비율을 유지하고 싶지만 전체 블리드 또는 다소 풍부한 브라우저 경험을하고 싶습니다. 비디오는 새 브라우저 창 크기를 수용하기 위해 위 또는 아래로 있어야하지만 브라우저 창 중앙에 위치해야합니다. 때로는 일부 비디오가 잘릴 것입니다. 순수한 JS를 사용하여 비디오 요소에 대한 배경 표지 CSS 속성을 다시 만들려고하는데, 그게 상상하는 데 도움이된다면. 불행하게도전체 블리드 동영상, 가로 세로 비율 유지, 중앙 자바 스크립트, 순수 자바 스크립트
function getWinSize(){
var wid = 0, hei = 0;
if (document.documentElement && document.documentElement.clientHeight){
wid = parseInt(window.innerWidth,10);
hei = parseInt(window.innerHeight,10);
} else if (document.body){
wid = parseInt(document.body.offsetWidth,10);
hei = parseInt(document.body.offsetHeight,10);
}
return [wid,hei];
}
this.resize2 = function(){
fullBleedVideoPlayer();
};
function fullBleedVideoPlayer() {
var viewport=getWinSize();
var videoRatio = 1080/1920;
var browserHeight = viewport[0];
var browserWidth = viewport[1];
var tmp_windowRatio = viewport[1]/viewport[0];
if (videoRatio > tmp_windowRatio) {
tmp_height = Math.round(browserWidth * videoRatio);
_player.style.width= browserWidth+ "px";
_player.style.height= tmp_height+ "px";
_player.style.marginLeft = 0 + 'px';
_player.style.marginTop = -Math.round((tmp_height - browserHeight)/2) + 'px';
} else {
tmp_width = Math.round(browserHeight * (1/videoRatio));
_player.style.width= tmp_width+ "px";
_player.style.height= browserHeight+ "px";
_player.style.marginLeft = -Math.round((tmp_width - browserWidth)/2) + 'px';
_player.style.marginTop = 0 + 'px';
}
}
,이 CSS가 재현되지 않습니다
.bkgdCover{
background: no-repeat center center;
-webkit-background-size: 100% 100%;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
다음
순수 자바 스크립트에서 동일한 작업을 수행하는 나의 시도이다 : 사람들을 위해 그 heres는 다음, 무엇인지 모르는 사람들 덮개. 내가 실수 한 곳을 보거나 자신을 똑같이 해낸다면, 나는 당신의 이야기를 듣고 싶습니다. 순수한 JS 솔루션 만하시기 바랍니다.
btw, 나는 CSS가 있다는 것을 알고 있지만, 내가 만들려고했던 부분은 요소의 위치와 위치를 확인하는 것이 었습니다. JS를 사용하여 쉽게이 작업을 수행 할 수 있습니다. –