最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

原生JS實現(xiàn)翻書特效

 更新時間:2021年10月15日 12:04:54   作者:aiguangyuan  
這篇文章主要為大家詳細介紹了原生JS實現(xiàn)翻書特效,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文給大家分享一個用原生JS實現(xiàn)的翻書效果圖,效果如下:

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

<!doctype html>
<html>
 
    <head>
        <meta charset="utf-8">
        <title>原生JS實現(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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

芦山县| 宁强县| 淮北市| 乌恰县| 衡山县| 清新县| 日土县| 壤塘县| 辽源市| 涞源县| 阳曲县| 凤山县| 东港市| 迁安市| 高州市| 彰武县| 漠河县| 邵武市| 当涂县| 宁远县| 台安县| 柘城县| 吉水县| 平顶山市| 图们市| 正宁县| SHOW| 惠东县| 大城县| 平原县| 芦山县| 嫩江县| 绥滨县| 略阳县| 顺昌县| 同仁县| 波密县| 凤台县| 雷山县| 乐山市| 泰和县|