Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

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

<head>
  <meta charset="UTF-8">
  <title>CSS3翻书效果</title>
  <style type="text/css">
    * {
      padding: 0;
      margin: 0;
    }

    body,
    html {
      height: 100%;
    }

    li {
      list-style: none;
    }

    body {
      -webkit-perspective: 2000px;
      -moz-perspective: 2000px;
      -ms-perspective: 2000px;
      perspective: 2000px;
      background-color: #212121;
    }

    .book {
      position: absolute;
      top: 30%;
      left: 40%;
      width: 500px;
      height: 500px;
      background-color: #fff;
      -webkit-transform: rotateX(30deg);
      -ms-transform: rotateX(30deg);
      -o-transform: rotateX(30deg);
      transform: rotateX(30deg);
    }

    /*开3D效果*/
    .pre-3d {
      -webkit-transform-style: preserve-3d;
      -moz-transform-style: preserve-3d;
      -ms-transform-style: preserve-3d;
      transform-style: preserve-3d;
    }

    .page {
      position: absolute;
      top: 0;
      left: 0;
      width: 500px;
      height: 500px;
      border: 1px solid #1976D2;
      text-align: center;
      -webkit-transform-origin: 0 50%;
      -moz-transform-origin: 0 50%;
      -ms-transform-origin: 0 50%;
      -o-transform-origin: 0 50%;
      transform-origin: 0 50%;
    }

    .front1 {
      background-color: paleturquoise;
    }

    .front2 {
      background-color: goldenrod;
    }

    img {
      width: 100%;
      height: 100%;
    }
  </style>
</head>

<body>
  <div class="book pre-3d" id="book">
    <!-- 后封面 -->
    <ul>
      <li class="" id="Rcover">ddds<img src="https://i.loli.net/2021/09/16/OUYR4JBGvwIN96V.jpg" alt=""></li>
      <!-- 书页 -->
      <li class="pre-3d  page front2">sssss<img src="https://i.loli.net/2021/09/16/6pwyWdDxrlCKPqR.jpg" alt=""></li>
      <li class="pre-3d  page front2">ddfdf<img src="https://i.loli.net/2021/09/16/unVSedITc8vyQGf.jpg" alt=""></li>
      <li class="pre-3d  page front2">第二页<img src="https://i.loli.net/2021/09/16/ZN3woeJ6BdQ7lbV.jpg" alt=""></li>
      <li class="pre-3d  page front2">第一页<img src="https://i.loli.net/2021/09/16/HXYhczlBO1dfFKC.jpg" alt=""></li>
      <!-- 书的封面 -->
      <li class="pre-3d  page front1">封面<img src="https://i.loli.net/2021/09/16/zDIraLYqNbQAxBP.jpg" alt=""></li>
    </ul>
  </div>
</body>
<script>
  var b = document.getElementById('book');
  var s = document.getElementsByTagName('li');
  var c = document.getElementById('Rcover');
  var i = 5;
  b.onclick = function() {
    if (i > 0) {
      s[i].style.transform = 'rotateY(-150deg)';
      s[i].style.transition = '3s';
      
      // 处理 z-index
      var elPageList = document.querySelectorAll('li')
      for (var j = 0; j < i; j++) {
        elPageList[j].style['z-index'] = 'auto'
      }
      elPageList[i].style['z-index'] = 6 - i
      console.log(i)
      console.log(elPageList[i])
      for (var k = i + 1; k < 6; k++) {
        elPageList[k].style['z-index'] = 6 - k
      }
      
      i--;
    }
  }
  c.onclick = function() {
    for (var j = 1; j < 6; j++) {
      s[j].style.transform = 'rotateY(0deg)';
      s[j].style.transition = '3s';
    }
    
    // 处理 z-index
    var elPageList = document.querySelectorAll('li')
    for (var k = 0; k < 6; k++) {
      elPageList[k].style['z-index'] = 'auto'
    }
    
    // 恢复i,还能继续从头开始翻
    setTimeout(() => {
      i = 5
    })
  }
</script>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console