Fullscreen 3D One Page Scrolling Effect with jQuery and CSS3

Fullscreen 3D One Page Scrolling Effect with jQuery and CSS3
File Size: 3.12 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Creating a fullscreen one page scrolling web page with a 3D curtain effect that reunites a list of split DIV blocks using CSS3 transitions & transforms and a little jQuery magic. Inspired by 3D Curtain Template.

How to use it:

1. Create a list of split blocks that reunite on scrolling.

<div class="scene">
  <div class="page page-1 active">
    <div class="half left"></div>
    <div class="half right withText">
      <h2 class="heading">Page 1</h2>
    </div>
  </div>
  <div class="page page-2">
    <div class="half left withText">
      <h2 class="heading">Page 2</h2>
    </div>
    <div class="half right"></div>
  </div>
  <div class="page page-3">
    <div class="half left"></div>
    <div class="half right withText">
      <h2 class="heading">Page 3</h2>
    </div>
  </div>
  <div class="page page-4">
    <div class="half left withText">
      <h2 class="heading">Page 4</h2>
    </div>
    <div class="half right"></div>
  </div>
</div>

2. Create a side navigation for the one page scrolling effect.

<div class="nav-panel">
  <div class="scroll-btn up"></div>
  <div class="scroll-btn down"></div>
  <nav>
    <ul>
      <li data-target="1" class="nav-btn nav-page1 active"></li>
      <li data-target="2" class="nav-btn nav-page2"></li>
      <li data-target="3" class="nav-btn nav-page3"></li>
      <li data-target="4" class="nav-btn nav-page4"></li>
    </ul>
  </nav>
</div>

3. The core CSS/CSS3 styles.

*,
*:before,
*:after {
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  font-size: 62.5%;
  font-size: 1rem;
  height: 100%;
  overflow: hidden;
  background: #000;
}
@media (max-width: 767px) {

html,
body { font-size: 80%; }
}
@media (max-width: 640px) {

html,
body { font-size: 60%; }
}
@media (max-width: 480px) {

html,
body { font-size: 40%; }
}

.inner,
.nav-panel ul .nav-btn:after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
}

.scene {
  width: 100%;
  height: 100%;
}

.page {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -webkit-transition: -webkit-transform .7s, opacity .7s;
  transition: transform .7s, opacity .7s;
  will-change: transform, opacity;
}

.page:nth-child(1) .left { background-image: url("http://i.imgur.com/fLYCaz8.jpg"); }

.page:nth-child(1) .right { background-image: url("http://i.imgur.com/uFJxGwc.jpg"); }

.page:nth-child(2) .left { background-image: url("http://i.imgur.com/scnm6Qu.jpg"); }

.page:nth-child(2) .right { background-image: url("http://i.imgur.com/feqYEnm.jpg"); }

.page:nth-child(3) .left { background-image: url("http://i.imgur.com/7y4mubP.jpg"); }

.page:nth-child(3) .right { background-image: url("http://i.imgur.com/IOPkwbL.jpg"); }

.page:nth-child(4) .left { background-image: url("http://i.imgur.com/KEnImct.jpg"); }

.page:nth-child(4) .right { background-image: url("http://i.imgur.com/bLvkYTs.jpg"); }

.page.active .half {
  -webkit-transform: translateX(0) !important;
  -ms-transform: translateX(0) !important;
  transform: translateX(0) !important;
  -webkit-transition: -webkit-transform .7s ease-out;
  transition: transform .7s ease-out;
}

.page.previous {
  opacity: 0.4 !important;
  visibility: visible !important;
}

.page.small {
  -webkit-transform: scale(0.8);
  -ms-transform: scale(0.8);
  transform: scale(0.8);
  opacity: 0;
}

.page.small .half {
  -webkit-transform: translateX(0) !important;
  -ms-transform: translateX(0) !important;
  transform: translateX(0) !important;
}

.page:nth-child(2) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(2) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(3) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(3) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(4) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(4) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(5) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(5) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(6) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(6) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(7) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(7) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(8) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(8) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(9) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(9) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.page:nth-child(10) .left {
  -webkit-transform: translateX(-100%);
  -ms-transform: translateX(-100%);
  transform: translateX(-100%);
}

.page:nth-child(10) .right {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
}

.half {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background-size: cover;
  -webkit-transition: -webkit-transform .7s ease-in;
  transition: transform .7s ease-in;
  will-change: transform;
}

.half.left { left: 0; }

.half.right { left: 50%; }

.half.withText:after {
  content: "";
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.heading {
  position: absolute;
  z-index: 500;
  top: 50%;
  left: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%);
  -ms-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
  font-size: 3.5rem;
  color: #fff;
  font-family: Decade;
}

4. Style the side navigation.

.nav-panel {
  position: fixed;
  top: 50%;
  right: 2%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  z-index: 1000;
  -webkit-transition: opacity 0.5s, -webkit-transform 0.5s cubic-bezier(0.57, 1.2, 0.68, 2.6);
  transition: opacity 0.5s, transform 0.5s cubic-bezier(0.57, 1.2, 0.68, 2.6);
  will-change: transform, opacity;
}

.nav-panel.invisible {
  opacity: 0;
  -webkit-transform: translateY(-50%) scale(0.5);
  -ms-transform: translateY(-50%) scale(0.5);
  transform: translateY(-50%) scale(0.5);
}

.nav-panel ul { list-style-type: none; }

.nav-panel ul .nav-btn {
  position: relative;
  overflow: hidden;
  width: 1rem;
  height: 1rem;
  margin-bottom: 0.5rem;
  border: 0.12rem solid #fff;
  border-radius: 50%;
  cursor: pointer;
  -webkit-transition: border-color, -webkit-transform 0.3s;
  transition: border-color, transform 0.3s;
  will-change: border-color, transform;
}

.nav-panel ul .nav-btn:after {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%) scale(0.3);
  -ms-transform: translateX(-50%) translateY(-50%) scale(0.3);
  transform: translateX(-50%) translateY(-50%) scale(0.3);
  background-color: #fff;
  opacity: 0;
  -webkit-transition: -webkit-transform, opacity 0.3s;
  transition: transform, opacity 0.3s;
  will-change: transform, opacity;
}

.nav-panel ul .nav-btn.active:after,
.nav-panel ul .nav-btn:hover:after {
  -webkit-transform: translateX(-50%) translateY(-50%) scale(0.7);
  -ms-transform: translateX(-50%) translateY(-50%) scale(0.7);
  transform: translateX(-50%) translateY(-50%) scale(0.7);
  opacity: 1;
}

.nav-panel ul .nav-btn:hover {
  border-color: yellow;
  -webkit-transform: scale(1.2);
  -ms-transform: scale(1.2);
  transform: scale(1.2);
}

.nav-panel ul .nav-btn:hover:after { background-color: yellow; }

.nav-panel .scroll-btn {
  position: absolute;
  left: 0;
  width: 1rem;
  height: 1rem;
  border: 0.2rem solid #fff;
  border-left: none;
  border-bottom: none;
  cursor: pointer;
  -webkit-transform-origin: 50% 50%;
  -ms-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  -webkit-transition: border-color 0.3s;
  transition: border-color 0.3s;
}

.nav-panel .scroll-btn.up {
  top: -1.6rem;
  -webkit-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  transform: rotate(-45deg);
}

.nav-panel .scroll-btn.down {
  bottom: -1.2rem;
  -webkit-transform: rotate(135deg);
  -ms-transform: rotate(135deg);
  transform: rotate(135deg);
}

.nav-panel .scroll-btn:hover { border-color: yellow; }

5. Load the needed jQuery library at the end of the document.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

6. The JavaScript to enable the one page scrolling effect. Make sure to add the following snippets after you have jQuery loaded.

$(document).ready(function() {
  
  var pages = $(".page").length,
      scrolling = false,
      curPage = 1;
  
  function pagination(page, movingUp) {
    scrolling = true;
    var diff = curPage - page,
        oldPage = curPage;
    curPage = page;
    $(".page").removeClass("active small previous");
    $(".page-" + page).addClass("active");
    $(".nav-btn").removeClass("active");
    $(".nav-page" + page).addClass("active");
    if (page > 1) {
      $(".page-" + (page - 1)).addClass("previous");
      if (movingUp) {
        $(".page-" + (page - 1)).hide();
        var hackPage = page;
        setTimeout(function() {
          $(".page-" + (hackPage - 1)).show();
        }, 600);
      }
      while (--page) {
        $(".page-" + page).addClass("small");
      }
    }
    console.log(diff)
    if (diff > 1) {
      for (var j = page + 1; j < oldPage; j++) {
        $(".page-" + j + " .half").css("transition", "transform .7s ease-out");
      }
    }
    setTimeout(function() {
      scrolling = false;
      $(".page .half").attr("style", "");
      $(".page")
    }, 700);
  }
  
  function navigateUp() {
    if (curPage > 1) {
      curPage--;
      pagination(curPage, true);
    }
  }

  function navigateDown() {
    if (curPage < pages) {
      curPage++;
      pagination(curPage);
    }
  }
  
  $(document).on("mousewheel DOMMouseScroll", function(e) {
    if (!scrolling) {
      if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
        navigateUp();
      } else { 
        navigateDown();
      }
    }
  });
  
  $(document).on("click", ".scroll-btn", function() {
    if (scrolling) return;
    if ($(this).hasClass("up")) {
      navigateUp();
    } else {
      navigateDown();
    }
  });
  
  $(document).on("keydown", function(e) {
    if (scrolling) return;
    if (e.which === 38) {
      navigateUp();
    } else if (e.which === 40) {
      navigateDown();
    }
  });
  
  $(document).on("click", ".nav-btn:not(.active)", function() {
    if (scrolling) return;
    pagination(+$(this).attr("data-target"));
  });

});

This awesome jQuery plugin is developed by suez. For more Advanced Usages, please check the demo page or visit the official website.