_css实现翻书效果">
赞
踩
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .contexts{ display: flex; width: 100%; height:100%; } .book-container { padding-left: 260px; } .book-container .book { position: relative; width: 160px; height: 220px; perspective: 1000px; transform-style: preserve-3d; } .book-container .book:hover .hardcover_front { transform: rotateY(-145deg) translateZ(0); z-index: 0; } .book-container .book:hover .page > li:nth-child(1) { transform: rotateY(-30deg); transition-duration: 1.5s; } .book-container .book:hover .page > li:nth-child(2) { transform: rotateY(-35deg); transition-duration: 1.8s; } .book-container .book:hover .page > li:nth-child(3) { transform: rotateY(-118deg); transition-duration: 1.6s; } .book-container .book:hover .page > li:nth-child(4) { transform: rotateY(-130deg); transition-duration: 1.4s; } .book-container .book:hover .page > li:nth-child(5) { transform: rotateY(-140deg); transition-duration: 1.2s; } .book-container .book li::before, .book-container .book li::after { content: ""; } .book-container .book ul { margin-bottom: 0; } .book-container .book .hardcover_front, .book-container .book .hardcover_back, .book-container .book .book_spine, .book-container .book .hardcover_front > li, .book-container .book .hardcover_back > li, .book-container .book .book_spine > li, .book-container .book .page > li { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform-style: preserve-3d; } .book-container .book .hardcover_front > li:first-child:after, .book-container .book .hardcover_front > li:first-child:before, .book-container .book .hardcover_front > li:last-child:after, .book-container .book .hardcover_front > li:last-child:before, .book-container .book .hardcover_back > li:first-child:after, .book-container .book .hardcover_back > li:first-child:before, .book-container .book .hardcover_back > li:last-child:after, .book-container .book .hardcover_back > li:last-child:before, .book-container .book .book_spine > li:first-child:after, .book-container .book .book_spine > li:first-child:before, .book-container .book .book_spine > li:last-child:after, .book-container .book .book_spine > li:last-child:before { position: absolute; top: 0; left: 0; } .book-container .hardcover_front { transition: all 0.8s ease; transform-origin: 0% 100%; transform: rotateY(-46deg) translateZ(8px); z-index: 100; } .book-container .hardcover_front > li:first-child { transform: translateZ(2px); background-color: #eee; } .book-container .hardcover_front > li:first-child::before, .book-container .hardcover_front > li:first-child::after { width: 3px; height: 100%; background: #999; } .book-container .hardcover_front > li:first-child::before { transform: rotateY(90deg) translateZ(-2px) translateX(2px); } .book-container .hardcover_front > li:first-child::after { transform: rotateY(90deg) translateZ(158px) translateX(2px); } .book-container .hardcover_front > li:last-child { transform: rotateY(180deg) translateZ(2px); background: #fffbec; } .book-container .hardcover_front > li:last-child::before { box-shadow: 0px 0px 30px 5px #333; transform: rotateX(90deg) rotateZ(90deg) translateZ(-140px) translateX(-2px) translateY(-78px); width: 4px; height: 160px; } .book-container .page { position: relative; width: 100%; height: 98%; top: 10%; left: 10%; z-index: 10; transform-style: preserve-3d; } .book-container .page > li { transform-origin: left center; transition-property: transform; transition-timing-function: ease; border-radius: 0px 5px 5px 0px; background: -webkit-linear-gradient(left, #e1ddd8 0%, #fffbf6 100%); box-shadow: inset 0px -1px 2px rgba(50, 50, 50, 0.1), inset -1px 0px 1px rgba(150, 150, 150, 0.2); } .book-container .page > li:nth-child(1) { transition-duration: 0.6s; transform: rotateY(-40deg); } .book-container .page > li:nth-child(2) { transition-duration: 0.6s; transform: rotateY(-42deg); } .book-container .page > li:nth-child(3) { transition-duration: 0.4s; transform: rotateY(-44deg); } .book-container .page > li:nth-child(4) { transition-duration: 0.5s; transform: rotateY(-46deg); } .book-container .page > li:nth-child(5) { transition-duration: 0.6s; transform: rotateY(-48deg); } .book-container .hardcover_back { transform-origin: 0% 100%; transform: rotateY(-32deg) translateZ(-18px); } .book-container .hardcover_back li:first-child { transform: translateZ(2px); background: #fffbec; } .book-container .hardcover_back li:first-child::before, .book-container .hardcover_back li:first-child::after { width: 4px; height: 100%; background: #999; } .book-container .hardcover_back li:first-child::before { transform: rotateY(90deg) translateZ(-2px) translateX(2px); } .book-container .hardcover_back li:first-child::after { transform: rotateY(90deg) translateZ(158px) translateX(2px); } .book-container .hardcover_back li:last-child { transform: translateZ(-2px); background: #fffbec; } .book-container .hardcover_back li:last-child::before, .book-container .hardcover_back li:last-child::after { width: 4px; height: 160px; background: #999; } .book-container .hardcover_back li:last-child::before { transform: rotateX(90deg) rotateZ(90deg) translateZ(-140px) translateX(2px) translateY(-78px); box-shadow: 10px -1px 80px 20px #666; } .cover-box { display: flex; flex-direction: column; justify-content: center; align-items: center; width: 100%; height: 100%; background: #6fb6e5; color: #fff; padding: 0 10px; font-size: 12px; text-align: center; } .cover-box .title { width: 100%; color: #fff; font-size: 16px; margin-bottom: 0; } .cover-box p { width: 100%; } .content-box { display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; } .content-box .btn { display: inline-block; color: #2c3e50; padding: 5px; cursor: pointer; transition: all 0.3s; } .content-box .btn a { color: #2c3e50; } </style> </head> <body> <div class="contexts" > <div class="book-container"> <div class="book"> <ul class="hardcover_front" style="list-style: none;"> <li> <div class='cover-box' style="background-color:#f3b47e ;"> <h3 class='title ellipsis'>五块钱如何花三天</h3> <p class='ellipsis'></p> </div> </li> <li></li> </ul> <ul class="page" style=" list-style: none;"> <li></li> <li> <div class='content-box'> <div class='btn'> <img src="https://tse2-mm.cn.bing.net/th/id/OIP-C.OU64L4-I-bzNtMMIuDobEgHaFj?w=238&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7" width="90%" height="90%"/> </div> </div> </li> <li></li> <li></li> <li></li> </ul> <ul class="hardcover_back" style="list-style: none;"> <li></li> <li></li> </ul> </div> </div> <div class="book-container"> <div class="book"> <ul class="hardcover_front" style="list-style: none;"> <li> <div class='cover-box' style="background-color:#83d3d3 ;"> <h3 class='title ellipsis'>养猪秘诀</h3> <p class='ellipsis'></p> </div> </li> <li></li> </ul> <ul class="page" style=" list-style: none;"> <li></li> <li> <div class='content-box'> <div class='btn'> <img src="https://tse2-mm.cn.bing.net/th/id/OIP-C.OU64L4-I-bzNtMMIuDobEgHaFj?w=238&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7" width="90%" height="90%"/> </div> </div> </li> <li></li> <li></li> <li></li> </ul> <ul class="hardcover_back" style=" list-style: none;"> <li></li> <li></li> </ul> </div> </div> <div class="book-container"> <div class="book"> <ul class="hardcover_front" style="list-style: none;"> <li> <div class='cover-box' style="background-color:#8bc2e8 ;"> <h3 class='title ellipsis'>如何能成为富豪</h3> <p class='ellipsis'></p> </div> </li> <li></li> </ul> <ul class="page" style=" list-style: none;"> <li></li> <li> <div class='content-box'> <div class='btn'> <img src="https://tse2-mm.cn.bing.net/th/id/OIP-C.OU64L4-I-bzNtMMIuDobEgHaFj?w=238&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7" width="90%" height="90%"/> </div> </div> </li> <li></li> <li></li> <li></li> </ul> <ul class="hardcover_back" style=" list-style: none;"> <li></li> <li></li> </ul> </div> </div> </div> </body> </html>
.book-container { padding-left: 200px; .book { position: relative; width: 160px; height: 220px; perspective: 1000px; transform-style: preserve-3d; &:hover { .hardcover_front { transform: rotateY(-145deg) translateZ(0); z-index: 0; } .page { &>li:nth-child(1) { transform: rotateY(-30deg); transition-duration: 1.5s; } &>li:nth-child(2) { transform: rotateY(-35deg); transition-duration: 1.8s; } &>li:nth-child(3) { transform: rotateY(-118deg); transition-duration: 1.6s; } &>li:nth-child(4) { transform: rotateY(-130deg); transition-duration: 1.4s; } &>li:nth-child(5) { transform: rotateY(-140deg); transition-duration: 1.2s; } } } //公共样式 li::before, li::after { content: ""; } ul{ margin-bottom: 0; } .hardcover_front, .hardcover_back, .book_spine, .hardcover_front>li, .hardcover_back>li, .book_spine>li, .page>li { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform-style: preserve-3d; } .hardcover_front>li:first-child:after, .hardcover_front>li:first-child:before, .hardcover_front>li:last-child:after, .hardcover_front>li:last-child:before, .hardcover_back>li:first-child:after, .hardcover_back>li:first-child:before, .hardcover_back>li:last-child:after, .hardcover_back>li:last-child:before, .book_spine>li:first-child:after, .book_spine>li:first-child:before, .book_spine>li:last-child:after, .book_spine>li:last-child:before { position: absolute; top: 0; left: 0; } } // 封面 .hardcover_front { transition: all 0.8s ease; transform-origin: 0% 100%; transform: rotateY(-34deg) translateZ(8px); z-index: 100; &>li:first-child { transform: translateZ(2px); background-color: #eee; &::before, &::after { width: 3px; height: 100%; background: #999; } &::before { transform: rotateY(90deg) translateZ(-2px) translateX(2px); } &::after { transform: rotateY(90deg) translateZ(158px) translateX(2px); } } &>li:last-child { transform: rotateY(180deg) translateZ(2px); background: #fffbec; &::before { box-shadow: 0px 0px 30px 5px #333; transform: rotateX(90deg) rotateZ(90deg) translateZ(-140px) translateX(-2px) translateY(-78px); width: 4px; height: 160px; } } } // 书页 .page { position: relative; width: 100%; height: 98%; top: 1%; left: 3%; z-index: 10; transform-style: preserve-3d; //父元素加了这个属性,子元素尽管用position属性设置z-index也不管用 &>li { transform-origin: left center; transition-property: transform; transition-timing-function: ease; border-radius: 0px 5px 5px 0px; background: -webkit-linear-gradient(left, #e1ddd8 0%, #fffbf6 100%); box-shadow: inset 0px -1px 2px rgba(50, 50, 50, 0.1), inset -1px 0px 1px rgba(150, 150, 150, 0.2); } &>li:nth-child(1) { transition-duration: 0.6s; transform: rotateY(-28deg); } &>li:nth-child(2) { transition-duration: 0.6s; transform: rotateY(-30deg); } &>li:nth-child(3) { transition-duration: 0.4s; transform: rotateY(-32deg); } &>li:nth-child(4) { transition-duration: 0.5s; transform: rotateY(-34deg); } &>li:nth-child(5) { transition-duration: 0.6s; transform: rotateY(-36deg); } } // 背面 .hardcover_back { transform-origin: 0% 100%; transform: rotateY(-15deg) translateZ(-8px); li:first-child { transform: translateZ(2px); background: #fffbec; &::before, &::after { width: 4px; height: 100%; background: #999; } &::before { transform: rotateY(90deg) translateZ(-2px) translateX(2px); } &::after { transform: rotateY(90deg) translateZ(158px) translateX(2px); } } li:last-child { transform: translateZ(-2px); background: #fffbec; &::before, &::after { width: 4px; height: 160px; //书的宽度 background: #999; } &::before { transform: rotateX(90deg) rotateZ(90deg) translateZ(-140px) translateX(2px) translateY(-78px); box-shadow: 10px -1px 80px 20px #666; } } } } .cover-box { display: flex; flex-direction: column; justify-content: center; align-items: center; width: 100%; height: 100%; background: #6fb6e5; color: #fff; padding: 0 10px; font-size: 12px; text-align: center; .title { width: 100%; color: #fff; font-size: 16px; margin-bottom: 0; } p { width: 100%; } } .content-box { display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; .btn { display: inline-block; border: 2px solid #2c3e50; color: #2c3e50; padding: 5px; cursor: pointer; transition: all .3s; a { color: #2c3e50; } &:hover { a { color: var(--primaryColor); } border: 2px solid var(--primaryColor); } } }
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。