Search code examples
javascriptcsspositioningfullscreenabsolute

place a relative div under an absolute divs generated height by window


Hey there :) I'm trying to make a video fit the browser window size plus adding an image at the bottom of the browser window height. So you get the video and the image to be the only thing that is showed when you load the page. When you scroll dowm the content of the website should appear.

I've made something to illustrate the idea: http://instagib.dk/JS-test/

The problem is when I start adding the content of the site, it appears under video and image. The problem seems to be I've made it absolute and out of the documents context.

Is there any JS, Jquery solution that reads the height of the absolute content and places content after the video?

Cheers:)

<body>
<!-- Header -->
<header class="header">
    <div class="header-bg">
        <div class="logo-top"></div>
    </div>
    <nav>
        <div class="menu">
            <div class="hamburger"></div>
            <div class="hamburger"></div>
            <div class="hamburger"></div>
            <ul class="nav-list">
                <li><a href="#">Projects</a></li>
                <li><a href="#">Services</a></li>
                <li><a href="#">Advantages</a></li>
                <li><a href="#">Who are we</a></li>
                <li><a href="#">Work with us</a></li>
            </ul>
        </div>

    </nav>
</header>
<video class="intro" autoplay loop>
    <source src="video/black_clouds.mp4" type="video/mp4">
        <source src="video/black_clouds.webm" type="video/webm">
            Your browser does not support the video tag.
</video>
<div class="intro-seperator"></div>

<!-- Main content -->
<main class="content">
</main>

<!-- Footer -->
<footer>
    <small>&copy; Crafthouse 2014</small>
</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(function() {

    divFade = $(".header-bg");

    var toggleHeader = function(noAnimate) {

        var threshold = 400,
            fadeLength = 300,
            opacity,
            scrollTop = $(document).scrollTop();

        if (scrollTop < threshold) {
            opacity = 0;
        } else if (scrollTop > threshold + fadeLength) {
            opacity = 1;
        } else {
            if (noAnimate) {
                opacity = 1;
            } else {
                opacity = (scrollTop - threshold) / fadeLength;
            }
        }

        divFade.css("opacity", opacity);

    };

    toggleHeader(true);
    $(window).scroll(function() {
        toggleHeader();
    });

});
</script>

The CSS:

    *, 
*:before, 
*:after {
    box-sizing: border-box;
}

body {
  font-family: 'Open Sans', sans-serif;
}
/*
  ========================================
  Layout: Header
  ========================================
*/

.header {
    width: 100%;
    height: 60px;
    position: fixed;
    top: 0px;
    color: #fff;
    z-index: 9999;
}

.header-bg {
    width: 100%;
    height: 60px;
    line-height: 60px;
    vertical-align: middle;
    background: #212121;
    position: absolute;
    opacity: 0;
    font-size: 25px;
}

.logo-top {
    background: url(../images/crafthouse-top-logo.png) no-repeat;
    width: 171px;
    height: 60px;
    margin: 0 auto;
}

.menu {
    width: 70px;
    height: 60px;
    padding-top: 20px;
    position: absolute;
    left: 8%;
}
.menu:hover {
    background: #000;
}
.hamburger {
    width: 30px;
    height: 3px;
    background: #fff;
    margin: 0 auto;
    margin-bottom: 5px;
}
.menu:hover .hamburger {
    background: #00ff91;
}

.nav-list {
    width: 150px;
    margin-top:20px;
    background: #000;
    display: none;
    padding: 20px 0 10px 18px;
    text-transform: uppercase;
}
.nav-list li {
   margin-bottom: 10px;
}
.nav-list li a {
  color: #fff;
  text-decoration: none;
  font-size: 14px;
}
.nav-list li a:hover {
  color: #00ff91;
}

.menu:hover .nav-list {
    display: block;
}


.intro {
    position: absolute;
    right: 0;
    bottom: 0;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    background-size: cover;
}

.intro-seperator {
    background: url(../images/seperator-brush-top.png);
    height: 164px;
    width: 100%;
    position: absolute;
    right: 0;
    bottom: 0;
}

.test {
    width: 100%;
    height: 100%;
    background: #fff;
}
/*
  ========================================
  Layout: Content
  ========================================
*/

.content {
    height: 2000px;
}

Solution

  • Use the following for your content:

    main{
        position:absolute;
        top:100%;
    }
    

    That moves the actual content below the video (assuming main is your content-element)