css - DIV Modernizr 中的 Drupal 响应式 HTML5 视频背景

标签 css html video drupal modernizr

我正在尝试实现 http://jsfiddle.net/mgmilcher/8R7Xx/sho/我的 Drupal 站点主页中的响应式 HTML5 视频背景,但未成功。通过将所有 html 代码复制到我的本地页面——front.tpl.php 页面,视频和文本出现了,但显然不是我想要的。一旦我将 CSS 添加到我的 style.css 表中,一切都消失了。我已经在本地将 JS 添加到站点,并且当前将它放在带有脚本 [] = 'name.js' 的“theme.info”文件中。不幸的是,这似乎对结果没有任何影响。我的主题基于 bootstrap,与创建此示例时使用的相同。

有没有人成功地将此示例实现到他们的 Drupal 站点中?我想要一个仅包含主要内容的响应式背景视频,我可以在其中添加其他内容 - 文本、视频,并且需要能够滚动才能查看视口(viewport)下方的内容。

<div class="homepage-hero-module">
    <div class="video-container">
        <div class="title-container">
            <div class="headline">
                    <h1>Welcome to our Company</h1>

            </div>
            <div class="description">
                <div class="inner">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</div>
            </div>
        </div>
        <div class="filter"></div>
        <video autoplay loop class="fillWidth">
            <source src="http://dfcb.github.io/BigVideo.js/vids/dock.mp4" type="video/mp4" />Your browser does not support the video tag. I suggest you upgrade your browser.</video>
        <div class="poster hidden">
            <img src="http://www.videojs.com/img/poster.jpg" alt="">
        </div>
    </div>
</div>

CSS

.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 .title-container {
  z-index: 1000;
  position: absolute;
  top: 35%;
  width: 100%;
  text-align: center;
  color: #fff;
}
.video-container .description .inner {
  font-size: 1em;
  width: 45%;
  margin: 0 auto;
}
.video-container .link {
  position: absolute;
  bottom: 3em;
  width: 100%;
  text-align: center;
  z-index: 1001;
  font-size: 2em;
  color: #fff;
}
.video-container .link a {
  color: #fff;
}
.video-container video {
  position: absolute;
  z-index: 0;
  bottom: 0;
}
.video-container video.fillWidth {
  width: 100%;
}

JS

/** Document Ready Functions **/
/********************************************************************/

$( document ).ready(function() {

    // Resive video
    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');
    });

});

/** Reusable Functions **/
/********************************************************************/

function scaleVideoContainer() {

    var height = $(window).height();
    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(),
        videoWidth,
        videoHeight;

    console.log(windowHeight);

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

        if (videoAspectRatio > windowAspectRatio) {
            videoWidth = windowWidth;
            videoHeight = videoWidth * videoAspectRatio;
            $(this).css({'top' : -(videoHeight - windowHeight) / 2 + 'px', 'margin-left' : 0});
        } else {
            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');


    });
}

我已经安装了 modernize 模块,还在我的 sites/all/libraries/modernizr 文件夹中包含了 modernizr.min.js

最佳答案

我不确定,但你确保额外的 js 文件存储在 sites/all/themes/THEME_NAME/js

因为 Drupal 不会运行自定义 js,除非它为每个需要它的主题存储在那里。

关于css - DIV Modernizr 中的 Drupal 响应式 HTML5 视频背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32621216/

相关文章:

CSS动画圆圈边框填充颜色

html - 灰色线条出现在 div 的背景图像周围

java - 如何使用变量作为 div 标题属性的值

html - 使用自定义网络播放器播放 YouTube 视频

html - 用html折叠表格

JQuery Lightbox 2 插件问题

jquery - Internet Explorer Div 对齐问题

javascript - 对输入使用自定义包装器 : pros and cons?

ios - 如何在 iOS 中播放循环视频?

html - 使用 HTML5 播放 HLS