纯css实现一个书本翻页动画效果代码

代码语言:html

所属分类:动画

代码描述:纯css实现一个书本翻页动画效果代码

代码标签: 一个 书本 翻页 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

 
<meta charset="UTF-8">

 
<style>
@import url("https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap");
:root {
 
--color-cover: hsl(0, 44%, 42%);
 
--color-cover-text: hsl(40, 64%, 80%);
 
--duration: 5000ms;
 
--initial-delay: 500ms;
}

body
{
 
display: flex;
 
height: 100vh;
 
margin: 0;
 
justify-content: center;
 
align-items: center;
 
font-family: "Cormorant Garamond", Garamond, "Times New Roman", Times, serif;
 
font-size: 20px;
 
background-color: aliceblue;
}

.book {
 
width: 67vh;
 
height: 100vh;
 
border-radius: 0 24px 24px 0;
 
transform-style: preserve-3d;
 
transform: scale(0.5) rotateX(60deg) rotateZ(30deg);
 
animation: move-book var(--duration) ease-in-out forwards;
 
animation-delay: var(--initial-delay);
}

.page {
 
position: absolute;
 
width: 100%;
 
height: 100%;
 
background-color: antiquewhite;
 
background: linear-gradient(to right, rgba(0, 0, 0, 0.1), transparent 10%) antiquewhite;
 
border: 1px solid rgba(0, 0, 0, 0.2);
 
border-radius: inherit;
 
z-index: calc(var(--pages) - var(--id, 0));
 
transform: translateZ(calc(var(--id, 0) * -1px));
 
transform-origin: 0 0;
 
animation: turn-page var(--duration) ease-in-out forwards;
 
--increment: calc(var(--duration) / (var(--pages) * 2));
 
animation-delay: calc( var(--id, 0) * var(--increment) + var(--initial-delay) * 2 );
}

main
.page {
 
animation: none;
 
padding: 32px;
 
box-sizing: border-box;
 
overflow-y: scroll;
 
z-index: 1;
}

.cover {
 
width: 100%;
 
height: 100%;
 
color: var(--color-cover-text);
 
z-index: var(--pages);
 
padding: 5%;
 
box-sizing: border-box;
 
font-size: clamp(12px, 2.2vh, 36px);
}
.cover .cover-content {
 
position: relative;
 
display: grid;
 
justify-items: center;
 
align-items: center;
 
grid-auto-rows: 1fr;
 
height: 90%;
 
width: 90%;
 
box-sizing: border-box;
 
margin: 5%;
 
padding: 5%;
 
border: 12px double var(--color-cover-text);
 
text-align: center;
}
.cover h1,
.cover h2 {
 
font-weight: 300;
}
.cover h1 {
 
text-transform: uppercase;
}
.cover img {
 
width: 50%;
 
filter: sepia(100%) brightness(85%) saturate(550%) hue-rotate(-10deg);
}

.cover,
.back,
.spine {
 
background: var(--color-cover);
}

.back {
 
transform: translateZ(calc(var(--pages) * -1px));
 
animation: none;
 
z-index: 0;
}

.spine {
 
position: absolute;
 
height: 100%;
 
width: calc(var(--pages) * 1px + 2px);
 
transform-origin: 100% 100%;
 
transform: translateZ(calc(var(--pages) * -1px)) translateX(calc(var(--pages) * -1px)) rotateY(90deg);
 
animation: fold-spine 3s ease-in-out forwards;
}

@keyframes move-book {
  from
{
   
perspective: 2000px;
   
transform: scale(0.5) rotateX(60deg) rotateZ(30deg);
 
}
  to
{
   
perspective: 5000px;
   
transform: scale(1) rotateX(0deg) rotateZ(0deg);
 
}
}
@keyframes fold-spine {
  from
{
   
transform: translateZ(calc(var(--pages) * -1px)) translateX(calc(var(--pages) * -1px)) rotateY(90deg);
 
}
  to
{
   
transform: translateZ(calc(var(--pages) * -1px)) translateX(calc(var(--pages) * -1px)) rotateY(0deg);
 
}
}
@keyframes turn-page {
  from
{
   
transform: translateZ(calc(var(--id, 0) * -1px)) rotateY(0);
 
}
  to
{
   
transform: translateZ(calc((var(--pages) - var(--id, 0)) * -1px)) rotateY(-180deg);
 
}
}
</style>


</head>

<body translate="no" >
 
<div class="book" style="--pages: 32">
 
<div class="cover page">
   
<div class="cover-content">
     
<h1>Alice in Wonderland</h1><img src="//repo.bfw.wiki/bfwrepo/image/5f802bd7cf212.png"/>
     
<h2>by Lewis Carroll</h2>
   
</div>
 
</div>
 
<div class="page" style="--id: 1"></div>
 
<div class="page" style="--id: 2"></div>
 
<div class="page" style="--id: 3"></div>
 
<div class="page" style="--id: 4"></div>
 
<div class="page" style="--id: 5"></div>
 
<div class="page" style="--id: 6"></div>
 
<div class="page" style="--id: 7"></div>
 
<div class="page" style="--id: 8"></div>
 
<div class="page" style="--id: 9"></div>
 
<div class="page" style="--id: 10"></div>
 
<div class="page" style="--id: 11"></div>
 
<div class="page" style="--id: 12"></div>
 
<div class="page" style="--id: 13"></div>
 
<div class="page" style="--id: 14"></div>
 
<div class="page" style="--id: 15"></div>
 
<div class="page" style="--id: 16"></div>
 
<div class="page" style="--id: 17"></div>
 
<div class="page" style="--id: 18"></div>
 
<div class="page" style="--id: 19"></div>
 
<div class="page" style="--id: 20"></div>
 
<div class="page" style="--id: 21"></div>
 
<div class="page" style="--id: 22"></div>
 
<div class="page" style="--id: 23"></div>
 
<div class="page" style="--id: 24"></div>
 
<div class="page" style="--id: 25"></div>
 
<div class="page" style="--id: 26"></div>
 
<div class="page" style="--id: 27"></div>
 
<div class="page" style="--id: 28"></div>
 
<div class="page" style="--id: 29"></div>
  <div class="p.........完整代码请登录后点击上方下载按钮下载查看

网友评论0