Key Takeaways: Code Overview <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <style> .book{ margin: auto; margin-top: 2rem; transform: translate(0,0); perspective: 5000px; max-width: 40%; height: 800px; position: relative; transition:all 1s ease; } .page{ position: absolute; width: 100%; height: 100%; top: 0; right: 0; background-color: pink; cursor: pointer; transition:all 1s ease; transform-origin: left center; transform-style: preserve-3d; } .active{ z-index: 1; } .page.flipped{ transform:rotateY(-180deg) } .back,.front{ text-align: center; position: absolute; backface-visibility: hidden; width: 100%; height: 100%; } .back{ transform:rotateY(180deg) } </style> <body> <div class="book"> <div class="page active"> <div class="front">Cover</div> <div class="back">1</div> </div> <div class="page"> <div class="front">2</div> <div class="back">3</div> </div> <div class="page"> <div class="front">4</div> <div class="back">5</div> </div> <div class="page"> <div class="front">6</div> <div class="back">Tail</div> </div> </div> </body> <script> let pages = document.getElementsByClassName('page') let book = document.getElementsByClassName('book')[0] function bookMove(drect){ if(drect==='right'){ book.style.transform = 'translate(50%,0)' }else if(drect==='left'){ book.style.transform = 'translate(0,0)' }else{ book.style.transform = 'translate(100%,0)' } } for(let i = 0;i<pages.length;i++){ pages[i].addEventListener('click',()=>{ if (pages[i].classList.contains('flipped')) { pages[i].classList.remove('flipped') pages[i].classList.add('active') if(i===0){ bookMove('left') } if (pages[i].nextElementSibling!==null){ pages[i].nextElementSibling.classList.remove('active') }else{ bookMove('right') } }else{ pages[i].classList.add('flipped') pages[i].classList.remove('active') if(i===0){ bookMove('right') } if (pages[i].nextElementSibling!==null){ pages[i].nextElementSibling.classList.add('active') }else{ bookMove('close') } } }) } </script> </html> Key points analysis Solve the display problem of page content: To solve the problem of centering pages in a book: This is the end of this article about the sample code for implementing the book page turning effect with CSS3. For more relevant CSS3 book page turning content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Comprehensive inventory of important log files in MySQL
>>: 11 Reasons Why Bootstrap Is So Popular
Initialize Data DROP TABLE IF EXISTS `test_01`; C...
need: Implement dynamic display of option values ...
Because the project needs to use https service, I...
//grammar: @media mediatype and | not | only (med...
User and Group Management 1. Basic concepts of us...
How to solve the problem of forgetting the root p...
Table of contents Install Docker on CentOS 8 1. U...
This article example shares the specific code of ...
Sometimes we want to execute a command in a conta...
Sophie Hardach Clyde Quay Wharf 37 East Soapbox Rx...
Many people say that IE6 does not support PNG tra...
Copy code The code is as follows: <!DOCTYPE ht...
Detailed explanation and examples of database acc...
MySQL download and installation (version 8.0.20) ...
The TextBox with the ReadOnly attribute will be di...