美文网首页页面特效
CSS+HTML<视觉差效果>

CSS+HTML<视觉差效果>

作者: 誰在花里胡哨 | 来源:发表于2019-11-20 14:27 被阅读0次
    效果图:
    move.gif
    利用Tweenlite实现效果,此处不做过多解释,详情可参考https://www.jianshu.com/p/c0575e62463d
    代码如下:
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            body,
            html {
                height: 100%;
            }
    
            body {
                margin: 0;
                width: 100%;
                display: flex;
                justify-content: center;
                align-items: center;
            }
    
            .bck {
                position: absolute;
                width: 100%;
                height: 100%;
                overflow: hidden;
                perspective: 3000px;
                display: flex;
                justify-content: center;
                align-items: center;
            }
    
            .block {
                width: 200px;
                height: 200px;
                position: relative;
                opacity: 0.8;
                cursor: pointer;
                transition: opacity 0.5s;
                border-radius: 50%;
                background: rgb(30, 209, 194);
                display: flex;
                justify-content: center;
                align-items: center;
                box-shadow: 2px 2px 5px #ccc;
            }
    
            .text {
                position: relative;
                display: inline-block;
                white-space: nowrap;
                font-size: 3rem;
                color: white;
                text-shadow: 2px 2px 5px rgb(131, 131, 131);
            }
        </style>
    </head>
    
    <body>
        <div class="bck">
            <div class="block">
                <h2 class="text">MOVE</h2>
            </div>
        </div>
    </body>
    <script src="js/TweenMax.min.js"></script>
    <script>
        //el 标签 shift 偏移量
        function mouseMoveChange(el, shift) {
            let _this = this;
            let dt = document.querySelectorAll(el);
            let w = window.innerWidth;
            let h = window.innerHeight;
            window.addEventListener("mousemove", function (e) {
                let x = e.pageX - w / 2;
                let y = e.pageY - h / 2;
                // Back还可设定强度,如ease: Back.easeOut.config(1.7)
                // Elastic还可设定强度,如ease: Elastic.easeOut.config(1, 0.3)
                // SlowMo还可设定强度,如ease: SlowMo.ease.config(0.7, 0.7, false)
                // SteppedEase还可设定阶数,如ease: SteppedEase.config(12)
                TweenLite.to(dt, 0, {
                    ease: Linear,
                    left: -x / shift,
                    top: -y / shift
                });
            });
        }
        mouseMoveChange(".block", 20);
        mouseMoveChange(".text", 50);
    </script>
    
    </html>
    

    相关文章

      网友评论

        本文标题:CSS+HTML<视觉差效果>

        本文链接:https://www.haomeiwen.com/subject/oleoictx.html