2016-06-16 15 views
2

私はビデオヘッダーを作成しようとしていますが、試してみると、あまりにも多く塗り潰されているように見えます。元のサイズが非常に大きい(私は小さなモニターを使用しています)か、サイズが変わるか、消えます。画面サイズに合わせてビデオヘッダーを取得できませんか?

また、ビデオのZインデックスが他の要素よりも低くなっていても、テキストとボタンがサイドに押し出されます。ビデオを画面に合わせることができないようです。私は元のバナー画像のためにそれをやってきましたが、何らかの理由でビデオ用にできませんでした。

HTML:

<!-- Header --> 
<header id="top" class="header"> 
     <div class="videoCont"> 
     <video id="rndmVid" autoplay loop muted> 
     <source src="http://convio.cancer.ca/mUFE/2016/one/videos/flower.mp4" type="video/mp4"> 
     </video> 
     </div> 
     <div class="text-vertical-center"> 
      <h1>Event Title</h1> 
      <h3>Tag Line</h3> 
      <br> 
      <a href="#about" class="btn-dark btn-lg">Learn More</a> 
<p>&nbsp;</p> 

//log-in html code 

</header> 

CSS:あなたのバナー画像と、私は、アップロードバナー画像を残してきた映像との比較を示す目的のために

video { 
    height: 100%; 
    width: 100%; 
    z-index: -1; 

} 

.header { 
    display: table; 
    position: relative; 
    width: 100%; 
    height: 100%; 
    background: url(http://convio.cancer.ca/mUFE/2016/one/img/cliffside.jpg) no-repeat center center scroll; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    background-size: cover; 
    -o-background-size: cover; 

} 


.header h1 { 
    font-size: 6.5em; 
    color: #FFF; 
    text-shadow: 2px 2px 2px rgb(0,0,0); 
} 

.header h3{ 
    font-size: 4em; 
    color: #fff; 
    text-shadow: 2px 2px 2px rgb(0,0,0); 
} 

。ここに表示されているように、test pageのテキストはビデオでプッシュオフされます(ビデオをz-index: -9999;に設定しても)。画像がページをスクロールさせる原因にならないことがわかります。私はビデオのためにこれを複製することはできません。

私は解決策を見つけようとしていますが、運がないとstackoverflowで3〜4の関連スレッドを行ってきました。すべての提案は非常に高く評価されています。

ありがとうございました!

答えて

3

を試してみてください。

video { 
 
    height: 100%; 
 
    width: 100%; 
 
} 
 

 
.videoCont { 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    z-index: 1; 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 

 
.text-vertical-center { 
 
    position: absolute; 
 
    text-align: center; 
 
    width: 100%; 
 
    height: 100%; 
 
    top: 0; 
 
    left: 0; 
 
    z-index: 10; 
 
}

ビデオのスタイルからZインデックスを移動しました。これは、座っているdivによく適用されます。 vid eoCont div私は絶対位置に設定しました。その幅は100%で、Z-インデックスは1です。 次に、テキスト垂直中心のdivがpositionの上に配置されます:position:absoluteを使用しますが、インデックス。

http://codepen.io/anon/pen/wWWOOB

編集:私は実際にフルスクリーンヒーローのビデオを設定するためのcoverr.coと呼ばれる時期にサービスを使用します。彼らは、HTML、CSS、およびJqueryのブロックを備えたサイトの基盤に大きなスニペットを持ち、これらを設定するのはかなり簡単です。また、古いブラウザのフォールバックとjpgフォールバックも処理します。

http://www.coverr.co/

彼らのコードは次のようになります。

//jQuery is required to run this code 
 
$(document).ready(function() { 
 

 
    scaleVideoContainer(); 
 

 
    initBannerVideoSize('.video-container .poster img'); 
 
    initBannerVideoSize('.video-container .filter'); 
 
    initBannerVideoSize('.video-container video'); 
 

 
    $(window).on('resize', function() { 
 
     scaleVideoContainer(); 
 
     scaleBannerVideoSize('.video-container .poster img'); 
 
     scaleBannerVideoSize('.video-container .filter'); 
 
     scaleBannerVideoSize('.video-container video'); 
 
    }); 
 

 
}); 
 

 
function scaleVideoContainer() { 
 

 
    var height = $(window).height() + 5; 
 
    var unitHeight = parseInt(height) + 'px'; 
 
    $('.homepage-hero-module').css('height',unitHeight); 
 

 
} 
 

 
function initBannerVideoSize(element){ 
 

 
    $(element).each(function(){ 
 
     $(this).data('height', $(this).height()); 
 
     $(this).data('width', $(this).width()); 
 
    }); 
 

 
    scaleBannerVideoSize(element); 
 

 
} 
 

 
function scaleBannerVideoSize(element){ 
 

 
    var windowWidth = $(window).width(), 
 
    windowHeight = $(window).height() + 5, 
 
    videoWidth, 
 
    videoHeight; 
 

 
    console.log(windowHeight); 
 

 
    $(element).each(function(){ 
 
     var videoAspectRatio = $(this).data('height')/$(this).data('width'); 
 

 
     $(this).width(windowWidth); 
 

 
     if(windowWidth < 1000){ 
 
      videoHeight = windowHeight; 
 
      videoWidth = videoHeight/videoAspectRatio; 
 
      $(this).css({'margin-top' : 0, 'margin-left' : -(videoWidth - windowWidth)/2 + 'px'}); 
 

 
      $(this).width(videoWidth).height(videoHeight); 
 
     } 
 

 
     $('.homepage-hero-module .video-container video').addClass('fadeIn animated'); 
 

 
    }); 
 
}
.homepage-hero-module { 
 
    border-right: none; 
 
    border-left: none; 
 
    position: relative; 
 
} 
 
.no-video .video-container video, 
 
.touch .video-container video { 
 
    display: none; 
 
} 
 
.no-video .video-container .poster, 
 
.touch .video-container .poster { 
 
    display: block !important; 
 
} 
 
.video-container { 
 
    position: relative; 
 
    bottom: 0%; 
 
    left: 0%; 
 
    height: 100%; 
 
    width: 100%; 
 
    overflow: hidden; 
 
    background: #000; 
 
} 
 
.video-container .poster img { 
 
    width: 100%; 
 
    bottom: 0; 
 
    position: absolute; 
 
} 
 
.video-container .filter { 
 
    z-index: 100; 
 
    position: absolute; 
 
    background: rgba(0, 0, 0, 0.4); 
 
    width: 100%; 
 
} 
 
.video-container video { 
 
    position: absolute; 
 
    z-index: 0; 
 
    bottom: 0; 
 
} 
 
.video-container video.fillWidth { 
 
    width: 100%; 
 
}
<div class="homepage-hero-module"> 
 
    <div class="video-container"> 
 
     <div class="filter"></div> 
 
     <video autoplay loop class="fillWidth"> 
 
      <source src="PATH_TO_MP4" type="video/mp4" />Your browser does not support the video tag. I suggest you upgrade your browser. 
 
      <source src="PATH_TO_WEBM" type="video/webm" />Your browser does not support the video tag. I suggest you upgrade your browser. 
 
     </video> 
 
     <div class="poster hidden"> 
 
      <img src="PATH_TO_JPEG" alt=""> 
 
     </div> 
 
    </div> 
 
</div>

+1

ああ、あんまりありがとう!これは素晴らしいことですが、私の問題を解決しただけでなく、ヒーローのビデオのための優れたリソースも私に提供しました。感謝万円! – Umeed

2

私はあなたのCSSを少し再編提案が、これは、あなたが希望しているものでない場合、私に知らせてくださいと思います。この

video { 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    min-width: 100%; 
    min-height: 100%; 
    width: auto; 
    transform: translateX(-50%) translateY(-50%); 
} 
+0

それが引き起こすところ、私が前に持っていたとして、残念ながらそれは私に同じ結果を与え、あなたの助けをありがとうページを水平方向にスクロールします。しかし、あなたは「イベントについて」の直前にちょうどいいと思っています。これは素晴らしいものです。これを別のプロジェクトに使うことができるかもしれません!ありがとう。 – Umeed

+1

うん、あなたは常にオーバーフローを設定することができます - x:水平スクロールを削除するために、本体に隠されて – alliuca

関連する問題