模仿實現百度搜索黑洞動畫效果

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>誅邪退避 百事無忌!!</title>
        <meta name="keywords" content="積極向上 能量滿滿" />
        <style type="text/css">
            * { margin: 0; padding: 0 }
            .ops-blackhole{
                width: 250px;
                height: 250px;
                animation-fill-mode: forwards;
                animation-timing-function:cubic-bezier(0,0,0,0);
                position: fixed; 
                overflow: hidden;
            }
            @keyframes mymove{  /*定義關鍵幀、scaleDrew是需要綁定到選擇器的關鍵幀名稱*/
                0%{
                    transform: scale(1) rotateZ(0deg);  /*開始爲原始大小*/
                }
                70%{
                    transform: scale(10) rotateZ(180deg);
                }
                100%{
                    transform: scale(0) rotateZ(360deg);   
                }
            }
            #hd2{
                width: 200px;
                height: 200px;
                position: absolute;
                left: 0px;
                top: 0px;
            }
            .changing {
                animation: rightMove 4s;
            }
        </style>
    </head>
    <body>
        <style type="text/css">
            * { margin: 0; padding: 0 }
            header{
                width: 100%;
                background-color: black;
                height: 70px;
                border-bottom: rgba(0, 0, 0, 0.22) 1px solid;
            }
            #nav{
                margin: 0 auto;
                width: 1000px;
                text-align: center;
                padding-top: 15px;
            }
            #nav ul li{
                line-height: 40px;
                display: inline;
            }
            #nav ul li a{
                color: rgba(255, 112, 87, 0.73);
                font-size: 17px;
                font-weight: bold;
                text-decoration: none;
                display: block;
                padding: 0 20px;
                margin-right: 10px;
                float: left;
            }
            #nav ul li a:hover,#nav_current{
                color: rgba(255, 129, 99, 0.91);
                background: rgb(5, 2, 2);
                box-shadow: 0px 1px 0px rgb(189, 226, 0), inset 0px 1px 1px rgb(202, 239, 0);
                border-radius: 15px; }
        </style>
        <header style='position:fixed'>
            <nav id="nav">
                <ul>
                    <li>
                        <a href="/" id="nav_current">贊贊首頁</a></li>
                    <li>
                        <a href="/" target="_blank" title="贊贊聯盟">贊贊聯盟</a></li>
                    <li>
                        <a href="/" target="_blank" title="贊贊熱點">贊贊熱點</a></li>
                    <li>
                        <a href="/" target="_blank" title="贊贊推薦">贊贊推薦</a></li>
                    <li>
                        <a href="/" target="_blank" title="花裏胡哨">花裏胡哨</a></li>
                    <li>
                        <a href="/" target="_blank" title="個人主頁">個人主頁</a></li>
                    <li>
                        <a href="/" target="_blank" title="模塊待開發">模塊待開發..</a></li>
                </ul>
                <!--獲取當前頁導航 高亮顯示標題--></nav>
        </header>
        <style type="text/css">
            .xz li{
                line-height: 40px;
                display: inline;
            }
        </style>
        <div>
            <div style='width:100%;height:75px' value='填充div'></div>
            <div style='text-align:content'>
                <div style='width:1000px;margin:0 auto;'>
                    <textarea name='selfzanzan' style="margin-left:5px;font-size:20px; width:650px;height:120px;resize: none;" maxlength="500"></textarea>
                    <div style='display:inline-block;height:120px'>
                        <ul class='xz' style='position:absolute;width:300px;'>
                            <li>
                                <input type='button' class='runButton' value='誅邪退避' style='height:120px'>
                            </li>
                            <li>
                                <input type='button' class='box' value='放下屠刀' style='position:absolute;left:65px;top:0px;height:120px;z-index:9999;'>
                            </li>
                            <li>
                                <input type='button' class='box1' value='輾轉反側' style='position:absolute;left:130px;top:0px;height:120px;z-index:9999;'>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>


        <!-- 隱藏層 -->
        <div style='width:100%;background-color:#afafbd'>
            <div>
                <div>
                    <img id='hd' src="blackhole2019_pc.png" class="ops-blackhole" style='display:none'>
                </div>
            </div>            
        </div>
        <script>
            // onclick='myFunction()'
            var x = document.getElementById("hd");
            // 使用 JavaScript 開始動畫
            function myFunction() {
                x.style.WebkitAnimation = "mymove 5s"; // Chrome, Safari 和 Opera 代碼
                x.style.display = 'block';

                //可視區的寬/高(DOM)
                //offsetHeight(帶邊框)和clientHeight(不帶邊框)
                var he = document.documentElement.clientHeight;
                var wi = document.documentElement.clientWidth;

                x.style.left = String(wi / 2 -100) + 'px' 
                x.style.top = String(he / 2 - 100) + 'px'

            }
            x.addEventListener("webkitAnimationEnd", myEndFunction);
            x.addEventListener("animationend", myEndFunction);

            function myEndFunction() {
                this.style.display = 'none';
            }

            document.querySelector(".runButton").addEventListener("click", play, false);

            function play() {
                myFunction();
                document.querySelector(".box").className = "box";
                document.querySelector(".box1").className = "box1";
                var he = document.documentElement.clientHeight;
                var wi = document.documentElement.clientWidth;
                var style = document.styleSheets[0];
                console.log(he,wi)
                style.insertRule('@keyframes rightMove{100% {animation-timing-function: linear;transform: scale(0);position:absolute;top:350px;left:-300px;}}');
                window.requestAnimationFrame(function(time) {
                    window.requestAnimationFrame(function(time) {
                    document.querySelector(".box").className = "box changing";
                    document.querySelector(".box1").className = "box1 changing";

                    });
                });
            }
        </script>
        <div style='width:100%;height:1200px;background-color:rgba(1,22,11,22)'>
        </div>
        <div>
            
        </div>
    </body>
</html>

百度的圖片是png的!!!

GIF 展示  有點失幀!

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章