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

              
                .container
  .hint * Click the book to open it!
  .mobile
    .content
      .book
        .cover
          .bend
        .pages.hide
            .page
              .pages-content
                .content-inner
                  .title Chapter 1
                  .text
                    p Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.
                .page-number - 1 -
            .page
              .pages-content
                .content-inner
                  .text
                    p Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.
                .page-number - 2 -
            .page
              .pages-content
                .content-inner
                  .text
                    p Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.Voluptas ea non vitae a assumenda sint quod, dolores laboriosam velit corrupti nobis cupiditate perspiciatis natus exercitationem, architecto esse ratione blanditiis! Itaque.
                .page-number - 3 -
            .page
              .pages-content
                .content-inner
                  .title Fin.
                  
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300;400&display=swap');

/** Theme **/

$theme-white: #fff;
$theme-black: #000;
$theme-purple: #50507f;
$theme-light-silver: #fafafa;
$book-text-color: #444444;

/** Dimensions **/

$container-width: 100vw;
$container-height: 100vh;

$mobile-width: 280px;
$mobile-height: 450px;
$mobile-padding: 15px;

$content-width: calc(#{$mobile-width} - (2 * #{$mobile-padding}));
$content-height: calc(#{$mobile-height} - (2 * #{$mobile-padding}));
$content-padding: $mobile-padding;
$content-border-radius: 10px;

$book-width: 125px;
$book-height: 200px;
$book-border-radius: 5px;

/** Font Sizes **/
$h1: 40px;
$h2: 35px;
$h3: 30px;
$h4: 25px;
$h5: 20px;
$regular17: 17px;
$regular: 16px;
$regular15: 15px;
$medium: 12px;
$small: 9px;
$tiny: 7px;

/** mixins **/

@mixin flex($justify: center, $align: center) {
  display: flex;
  justify-content: $justify;
  align-items: $align;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Source Sans Pro', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.container {
  position: relative;
  width: $container-width;
  height: $container-height;
  background-color: $theme-light-silver;
  @include flex();
  .hint {
    position: absolute;
    bottom: 25px;
  }
  .mobile {
    width: $mobile-width;
    height: $mobile-height;
    padding: $mobile-padding;
    .content {
      position: relative;
      width: $content-width;
      height: $content-height;
      border-radius: $content-border-radius;
      box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034),
        0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06),
        0 22.3px 17.9px rgba(0, 0, 0, 0.072),
        0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12);
      background-color: $theme-white;
      overflow: hidden;
      perspective: 1200px;
      @include flex();
      flex-direction: column;
      .book {
        position: relative;
        user-select: none;
        @include flex();
        .cover {
          position: absolute;
          width: 150px;
          height: 225px;
          background-image: url('https://res.cloudinary.com/dmfs0huzz/image/upload/v1597154148/stories-of-the-saints_sxtxjl.jpg');
          background-repeat: no-repeat;
          background-size: cover;
          border-top-left-radius: 5px;
          border-top-right-radius: 10px;
          border-bottom-left-radius: 5px;
          border-bottom-right-radius: 10px;
          box-shadow: 0 12px 6px -6px rgba(0, 0, 0, .4),
            -8px 12px 6px -6px rgba(0, 0, 0, .2),
            8px 12px 6px -6px rgba(0, 0, 0, .2);
          transition: transform 0.9s cubic-bezier(0.645, 0.045, 0.355, 1);
          &.active {
            width: 100%;
            height: 100%;
            transform: rotateY(-180deg);
            transform-origin: top left;
          }
          .bend {
            content: '';
            position: absolute;
            width: 2px;
            height: 100%;
            left: 10px;
            background-color: rgba(0, 0, 0, 0.25);
            box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.4);
          }
          &:hover {
            cursor: pointer;
          }
        }
        .pages {
          border-radius: $content-border-radius;
          .page {
            position: relative;
            background-color: $theme-white;
          }
          .pages-content {
            text-align: center;
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 15px;
            @include flex();
            .content-inner {
              text-align: center;
              opacity: 0;
              .title {
                font-size: 18px;
                font-weight: 400;
                padding-bottom: 10px;
                color: $book-text-color;
              }
              .text {
                text-align: justify;
                font-size: 12px;
                font-weight: 300;
                color: $book-text-color;
              }
            }
            .page-number {
              position: absolute;
              bottom: 15px;
              font-size: 12px;
              font-weight: 300;
              color: $book-text-color;
            }
          }
          &:hover {
            cursor: pointer;
          }
        }
      }
      &.active {
        position: relative;
      }
    }
  }
}

.hide {
  display: none !important;
}

              
            
!

JS

              
                /*
  * Inspired from - https://dribbble.com/shots/13926352-E-Book-Page-Swipe-Animaiton
  * Do check Saptarshi Prakash's bio for more awesome designs
*/

const $pages = $('.pages'),
      $cover = $('.cover'),
      $book = $(".book"),
      $hint = $(".hint"),
      timeline = new TimelineLite({ paused: true, reversed: true }),
      transitionSpeed = 1;

timeline.to(".bend", 0, { width: "0" }, 0)
        .to(".book", 0, { width: "100%", height: "100%"}, 0)
        .to(".cover", transitionSpeed, { className: "+=active", ease: Ease.easeIn, onComplete: () => {
          $pages.removeClass("hide");
          $cover.addClass("hide");
        } }, 0)
        .to(".content-inner", transitionSpeed, { opacity: 1 }, transitionSpeed);

$cover.on("click", function(){  
  $hint.text("* Use the corners to turn the page");
  timeline.play();
  $(".content").addClass("active");
  $pages.turn({
    duration: 1500,
    width: 250,
    height: 420,
    display: 'single',
    turnCorners: "bl,br",
    elevation: 300
  });
});

              
            
!
999px

Console