Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="book">
  <div class="Wrapper">
    <div class="cardCont">
      <div class="cardFront" id="page1"><h1>Page 1</h1></div>
      <div class="cardBack" id="page2"><h1>Page 2</h1></div>
    </div>
    <div class="cardCont">
      <div class="cardFront" id="page3"><h1>Page 3</h1></div>
      <div class="cardBack" id="page4"><h1>Page 4</h1></div>
    </div>
    <div class="cardCont">
      <div class="cardFront" id="page5"><h1>Page 5</h1></div>
      <div class="cardBack" id="page6"><h1>Page 6</h1></div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background: #e3dfd8;
  overflow: hidden;
}

.book {
  width: 72vw;
  height: 25vw;
  background: #e3dfd8;
  position: absolute;
  top: 50%;
  left: 50%;  
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.Wrapper {
  width: 72vw;
  height: 24vw;
  position: relative;
  position: absolute;
  cursor: pointer;
  -webkit-font-smoothing: antialiased;
}

.cardCont {
  width: 36vw;
  height: 24vw;
  left: 0%;
  position: absolute;
  pointer-events: none;
}

.cardFront,
.cardBack {
  pointer-events: all;
  position: absolute;
  left: 100%; 
  /*-webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
   backface-visibility: hidden;*/
  width: 36vw;
  height: 24vw;
  overflow: hidden;
  background: hsla(0, 0%, 100%, 1);
}
.cardFront {
  border-top-right-radius: 1%;
  border-bottom-right-radius: 1%;
}
.cardBack {
  border-top-left-radius: 1%;
  border-bottom-left-radius: 1%;
  left: 0%;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
   backface-visibility: hidden;
}

#page1:before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 2;
  pointer-events: none;
}

#page2:before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.2);
  z-index: 2;
  pointer-events: none;
}

#page3:before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 2;
  pointer-events: none;
}

#page4:before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.2);
  z-index: 2;
  pointer-events: none;
}

#page5:before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 2;
  pointer-events: none;
}

#page6:before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.2);
  z-index: 2;
  pointer-events: none;
}

.cardBack h1,
.cardFront h1 {
  margin: 0px;
  font-size: 30px;
  padding: 10px 0px 10px 10px;
  border-bottom: solid 6px #aaa;
  border-top: solid 6px #aaa;
  background-color: black;
  color: white;
}

.cardBack h1 {
  border-color: #91e600;
}
              
            
!

JS

              
                $(document).ready(function(){

$(window).on("load",function(){

//CSSPlugin.defaultTransformPerspective = 5000;
var numberOfPages = $('.Wrapper').children().length;
var hoverTarget; //stores currently hovered page, will only remove the hover effect if it hasn't been turned.
var PagesMoving = false; //prevents the pages getting out of order with multiple page clicks running simultaneously

//set the 3d perspective and initiate the back pages so it's rotated to the correct position
TweenLite.set(".book", {
  transformStyle: "preserve-3d"
});
TweenLite.set(".Wrapper", {
  transformStyle: "preserve-3d",
  transformOrigin: '50% 0%',
  rotationX: 12
});
TweenLite.set(".cardCont", {
  transformStyle: "preserve-3d"
});
TweenMax.set(".cardBack", {
  transformStyle: "preserve-3d",
  transformOrigin: '100% 50%',
  rotationY: 180,
  transformPerspective: 5000
});
TweenMax.set(".cardFront", {
  transformStyle: "preserve-3d",
  transformOrigin: '0% 50%',
  transformPerspective: 5000
});

// functions that set the z-index after a page has been moved
function setZIndexLeft(element, index) {
  element.css('z-index', (index + 1));
}

function setZIndexRight(element, index) {
  element.css('z-index', (numberOfPages - index) + 1);
}

//function that runs on completion of a page move
function pageTurnComplete() {
  PagesMoving = false;
}

//set initial z-index
var pages = $('.Wrapper').children();
pages.each(function(i) {
  var page = $(this);
  page.css('z-index', (numberOfPages - i) + 1); 
});

// turn pages on click - needs a function for the front of a page (i.e. one on the right hand side) and the back (on the left hand side)
$('.cardFront').click(function() {
  if (PagesMoving != true) {
    PagesMoving = true;
    var frontCard = $(this),
      backCard = $(this).parent(".cardCont").children(".cardBack"),
      element = $(this).parent(".cardCont"),
      parentPage = $(this).parent(".cardCont"),
      indexOf = (2 * (parentPage.index()+1) - 1),
      indexOf2 = indexOf + 1,
      tl = new TimelineMax({
        paused: false
      });
      var pageName = "#page" + indexOf + ":before",
          pageName2 = "#page" + indexOf2 + ":before",
          pageToDim = CSSRulePlugin.getRule(pageName),
          pageToDim2 = CSSRulePlugin.getRule(pageName2);

    hoverTarget = -1;
    console.log(hoverTarget);

    tl
      .to(frontCard, 1.4, {
        rotationY: -180,
        ease: Power1.easeInOut
      })
      .to(pageToDim, 0.7, {
        cssRule: { background: 'rgba(0, 0, 0, 0.2)' },
        ease: Power1.easeInOut
      }, 0)
      .to(pageToDim2, 0.7, {
        cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
        ease: Power1.easeInOut,
        onComplete: pageTurnComplete
      }, 0.7)
      .to(backCard, 1.4, {
        rotationY: 0,
        ease: Power1.easeInOut,
        onComplete:setZIndexLeft,
        onCompleteParams :[parentPage,parentPage.index()]
      }, 0);
  }
});

// turn pages on click - needs a function for the back (on the left hand side) and the front of a page (i.e. one on the right hand side) 
$('.cardBack').click(function() {
  if (PagesMoving != true) {
    PagesMoving = true;
    console.log("back clicked");
    var frontCard = $(this).parent(".cardCont").children(".cardFront"),
      backCard = $(this),
      element = $(this).parent(".cardCont"),
      parentPage = $(this).parent(".cardCont"),
      indexOf = (2 * (parentPage.index()+1) - 1),
      indexOf2 = indexOf + 1,
      tl = new TimelineMax({
        paused: false
      });
      var pageName = "#page" + indexOf + ":before",
          pageName2 = "#page" + indexOf2 + ":before",
          pageToDim = CSSRulePlugin.getRule(pageName),
          pageToDim2 = CSSRulePlugin.getRule(pageName2);

    hoverTarget = -1;
    console.log(hoverTarget);

    tl
      .to(frontCard, 1.4, {
        rotationY: 0,
        ease: Power1.easeInOut
      })
      .to(pageToDim2, 0.7, {
        cssRule: { background: 'rgba(0, 0, 0, 0.2)' },
        ease: Power1.easeInOut
      }, 0)
      .to(pageToDim, 0.7, {
        cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
        ease: Power1.easeInOut
      }, 0.7)
      .to(backCard, 1.4, {
        rotationY: 180,
        ease: Power1.easeInOut,
        onStart:setZIndexRight,
        onStartParams :[parentPage,parentPage.index()],
        onComplete: pageTurnComplete
      }, 0);
  }
});

//raise pages on hover, again, one set of functions for the front and back of the pages
$(".cardFront").hover(elOverFront, elOutFront);

function elOverFront()
{
    if((!TweenMax.isTweening()) && (PagesMoving == false)) {      
      var frontCard = $(this),
      backCard = $(this).parent(".cardCont").children(".cardBack"),
      element = $(this).parent(".cardCont"),
      parentPage = $(this).parent(".cardCont"),
      indexOf = (2 * (parentPage.index()+1) - 1),
      tl = new TimelineMax({
        paused: false
      }),
      pageName = "#page" + indexOf + ":before",
      pageToDim = CSSRulePlugin.getRule(pageName);
      
      hoverTarget = indexOf;
      console.log(hoverTarget);

    tl
      .to(frontCard, 0.4, {
        rotationY: -10,
        ease: Power1.easeInOut
      })
      .to(pageToDim, 0.4, {
        cssRule: { background: 'rgba(0, 0, 0, 0.05)' },
        ease: Power1.easeInOut
      }, 0);
    }
}

function elOutFront()
{
  if((!TweenMax.isTweening()) && (PagesMoving == false)) {
    var frontCard = $(this),
    backCard = $(this).parent(".cardCont").children(".cardBack"),
    element = $(this).parent(".cardCont"),
    parentPage = $(this).parent(".cardCont"),
    indexOf = (2 * (parentPage.index()+1) - 1);
    
    if (hoverTarget == indexOf) {
    
      var tl = new TimelineMax({
        paused: false
      }),
      pageName = "#page" + indexOf + ":before",
      pageToDim = CSSRulePlugin.getRule(pageName);

    tl
      .to(frontCard, 0.4, {
        rotationY: 0,
        ease: Power1.easeInOut
      })
      .to(pageToDim, 0.4, {
        cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
        ease: Power1.easeInOut
      }, 0);
    }
  }
}

//raise pages on hover, again, one set of functions for the front and back of the pages
$(".cardBack").hover(elOverBack, elOutBack);

function elOverBack()
{
    if((!TweenMax.isTweening()) && (PagesMoving == false)) {
      var frontCard = $(this).parent(".cardCont").children(".cardFront"),
      backCard = $(this),
      element = $(this).parent(".cardCont"),
      parentPage = $(this).parent(".cardCont"),
      indexOf = 2 * (parentPage.index()+1),
      tl = new TimelineMax({
        paused: false
      }),
      pageName = "#page" + indexOf + ":before",
      pageToDim = CSSRulePlugin.getRule(pageName);
      
      hoverTarget = indexOf;
      console.log(hoverTarget);

    tl
      .to(backCard, 0.4, {
        rotationY: 10,
        ease: Power1.easeInOut
      })
      .to(pageToDim, 0.4, {
        cssRule: { background: 'rgba(0, 0, 0, 0.05)' },
        ease: Power1.easeInOut
      }, 0);
    }
}

function elOutBack()
{
  if((!TweenMax.isTweening()) && (PagesMoving == false)) {
    var frontCard = $(this).parent(".cardCont").children(".cardFront"),
      backCard = $(this),
      element = $(this).parent(".cardCont"),
      parentPage = $(this).parent(".cardCont"),
      indexOf = 2 * (parentPage.index()+1);
    
    if (hoverTarget == indexOf) {
    
      var tl = new TimelineMax({
        paused: false
      }),
      pageName = "#page" + indexOf + ":before",
      pageToDim = CSSRulePlugin.getRule(pageName);

    tl
      .to(backCard, 0.4, {
        rotationY: 0,
        ease: Power1.easeInOut
      })
      .to(pageToDim, 0.4, {
        cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
        ease: Power1.easeInOut
      }, 0);
    }
  }
}
  
});
  
});
              
            
!
999px

Console