在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
关键要点: 代码总览 <!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">封面</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">尾面</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> 要点分析 解决页面内容的显示问题: 解决书本居中页面的问题: 到此这篇关于css3实现书本翻页效果的示例代码的文章就介绍到这了,更多相关css3 书本翻页内容请搜索极客世界以前的文章或继续浏览下面的相关文章,希望大家以后多多支持极客世界! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论