页面特效

CSS+HTML<视觉差效果>

2019-11-20  本文已影响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>
上一篇下一篇

猜你喜欢

热点阅读