Native JS to achieve book flipping effects

Native JS to achieve book flipping effects

This article shares with you a book flipping effect diagram implemented with native JS. The effect is as follows:

The implementation code is as follows, you are welcome to copy and paste.

<!doctype html>
<html>
 
    <head>
        <meta charset="utf-8">
        <title>Native JS to achieve book flipping effects</title>
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
                list-style: none;
            }
 
            #btn {
                width: 50px;
                height: 40px;
                line-height: 40px;
                position: relative;
                left: 50%;
                margin-left: -25px;
                top: 100px;
            }
 
            #book {
                width: 600px;
                height: 400px;
                position: absolute;
                left: 50%;
                top: 50%;
                margin: -200px 0 0 -300px;
                border: 1px solid black;
                /* First cover */
                background: url(images/0.jpg);
            }
 
            #rightPage {
                width: 50%;
                height: 100%;
                position: absolute;
                left: 50%;
                z-index: 2;
                transition: 0.5s;
                transform: perspective(800px) rotateY(0px);
                transform-origin: left center;
                background: black;
                transform-style: preserve-3d;
            }
 
            #rightPage #topNode {
                position: absolute;
                width: 100%;
                height: 100%;
                /* First cover */
                background: url(images/0.jpg) 300px 0;
                transform: translateZ(1px);
            }
 
            #rightPage #bottomNode {
                position: absolute;
                width: 100%;
                height: 100%;
                /* Third cover */
                background: url(images/2.jpg) 0 0;
                /*scaleX restores the image after flipping the book mirror*/
                transform: translateZ(-1px) scaleX(-1);
            }
 
            #rightOtherPage {
                position: absolute;
                left: 50%;
                height: 100%;
                width: 50%;
                /* Third cover */
                background: url(images/2.jpg) 300px 0;
                z-index: 1;
            }
        </style>
    </head>
 
    <body>
        <input type='button' value='Next page' id='btn'>
        <div id='book'>
            <div id='rightPage'>
                <div id='topNode'></div>
                <div id='bottomNode'></div>
            </div>
            <div id='rightOtherPage'></div>
        </div>
        <script type="text/javascript">
            var index = 0;
            var flag = false;
 
            btn.onclick = function () {
                if (flag) return;
                flag = true;
                index++;
                rightPage.style.transition = '0.5s';
                rightPage.style.transform = 'perspective(800px) rotateY(-180deg)';
 
                setTimeout(function () {
                    // Change the background of the next page instantly after turning the page book.style.backgroundImage = 'url(images/' + (index % 2 + 1) + '.jpg)';
                    // Let the page turn back instantlyrightPage.style.transition = '0s';
                    rightPage.style.transform = 'perspective(800px) rotateY(0deg)';
 
                    // Change the front background of the flip paper topNode.style.backgroundImage = 'url(images/' + (index % 2 + 1) + '.jpg)';
                    // Change the background of the back of the flip paper bottomNode.style.backgroundImage = 'url(images/' + ((index + 1) % 2 + 1) + '.jpg)';
 
                    // Change the paper background after turning the page rightOtherPage.style.backgroundImage = 'url(images/' + ((index + 1) % 2 + 1) + '.jpg)';
                    flag = false;
 
                }, 500);
 
            };
        </script>
    </body>
 
</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Turn.js asynchronous loading to achieve book flipping effect
  • Page switching style based on JS to achieve flip book effect
  • Native JS to achieve picture flipping effect
  • Realizing the book flipping effect based on Turn.js
  • Mobile H5 development Turn.js to achieve great book flipping effect
  • Realize 3D book flipping effects based on javascript html5
  • js picture flip book effect code sharing
  • JS to achieve the effect of picture flip book sample code

<<:  How to create Apache image using Dockerfile

>>:  Beginners learn some HTML tags (1)

Recommend

Sample code for nginx to achieve dynamic and static separation

1. Simple configuration of nginx's dynamic an...

Detailed explanation of the fish school algorithm in CocosCreator game

Preface I recently wanted to learn CocosCreator, ...

Detailed steps to upgrade mysql8.0.11 to mysql8.0.17 under win2008

Upgrade background: In order to solve the vulnera...

Understanding JavaScript prototype chain

Table of contents 1. Understanding the Equality R...

MySQL query_cache_type parameter and usage details

The purpose of setting up MySQL query cache is: C...

Analyze the working principle of Tomcat

SpringBoot is like a giant python, slowly winding...

Let's talk briefly about the changes in setup in vue3.0 sfc

Table of contents Preface Standard sfc writing me...

Detailed explanation of the order of JS object traversal

Some of you may have heard that the order of trav...

In-depth understanding of Vue-cli4 routing configuration

Table of contents Preface - Vue Routing 1. The mo...

Implementation of single process control of Linux C background service program

introduce Usually a background server program mus...

Detailed analysis of MySQL instance crash cases

[Problem description] Our production environment ...

JavaScript to achieve calendar effect

This article shares the specific code for JavaScr...

Windows DNS server exposed "worm-level" vulnerability, has existed for 17 years

Vulnerability Introduction The SigRed vulnerabili...