溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

原生JS實(shí)現(xiàn)翻書特效方法教程

發(fā)布時間:2021-10-15 13:31:19 來源:億速云 閱讀:142 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“原生JS實(shí)現(xiàn)翻書特效方法教程”,在日常操作中,相信很多人在原生JS實(shí)現(xiàn)翻書特效方法教程問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”原生JS實(shí)現(xiàn)翻書特效方法教程”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

效果如下:

原生JS實(shí)現(xiàn)翻書特效方法教程

實(shí)現(xiàn)代碼如下,歡迎大家復(fù)制粘貼。

<!doctype html>
<html>
 
    <head>
        <meta charset="utf-8">
        <title>原生JS實(shí)現(xiàn)翻書特效</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;
                /* 第一個封面 */
                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%;
                /* 第一個封面 */
                background: url(images/0.jpg) 300px 0;
                transform: translateZ(1px);
            }
 
            #rightPage #bottomNode {
                position: absolute;
                width: 100%;
                height: 100%;
                /* 第三個封面 */
                background: url(images/2.jpg) 0 0;
                /*scaleX將翻書鏡像后的圖像還原鏡像*/
                transform: translateZ(-1px) scaleX(-1);
            }
 
            #rightOtherPage {
                position: absolute;
                left: 50%;
                height: 100%;
                width: 50%;
                /* 第三個封面 */
                background: url(images/2.jpg) 300px 0;
                z-index: 1;
            }
        </style>
    </head>
 
    <body>
        <input type='button' value='下一頁' 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 () {
                    // 翻頁后瞬間更換下一頁的背景
                    book.style.backgroundImage = 'url(images/' + (index % 2 + 1) + '.jpg)';
                    // 讓翻頁瞬間回去
                    rightPage.style.transition = '0s';
                    rightPage.style.transform = 'perspective(800px) rotateY(0deg)';
 
                    // 更換翻頁紙正面背景
                    topNode.style.backgroundImage = 'url(images/' + (index % 2 + 1) + '.jpg)';
                    // 更換翻頁紙背面背景
                    bottomNode.style.backgroundImage = 'url(images/' + ((index + 1) % 2 + 1) + '.jpg)';
 
                    // 更換翻頁后的紙背景
                    rightOtherPage.style.backgroundImage = 'url(images/' + ((index + 1) % 2 + 1) + '.jpg)';
                    flag = false;
 
                }, 500);
 
            };
        </script>
    </body>
 
</html>

到此,關(guān)于“原生JS實(shí)現(xiàn)翻書特效方法教程”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

js
AI