react实现炫彩文字效果

代码语言:html

所属分类:动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <style>
        * {
            box-sizing: border-box;
            text-rendering: optimizeLegibility;
            -webkit-font-smoothing: antialiased;
        }
        body {
            background: #111;
        }
        #app {
            display: flex;
            place-items: center;
            min-height: 100vh;
        }
        .shimmer-text {
            position: absolute;
            top: 50%;
            left: 50%;
            -webkit-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
            width: 100vmin;
        }
        .shimmer-text svg {
            position: absolute;
            width: 100%;
            height: auto;
            font: bold 4rem sans-serif;
            text-transform: uppercase;
            -webkit-transform: translate(0, -50%);
            transform: translate(0, -50%);
        }
        .shimmer-text circle {
            fill: hsl(var(--hue,235), 100%, calc(var(--lightness, 50) * 1%));
        }
        .shimmer-text__text {
            fill: url("#shimmer-text__pattern");
        }
    </style>

</head>
<body translate="no">
    <div id="app"></div>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/dat.gui-min.js"></script>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/gsap.min.js"></script>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/react.dev.js"></script>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/react-dom.dev.js"></script>
   
    <script>
        const {
            gsap: {
                to,
                set,
                utils: {
                    random
                }
            },

            dat: {
                GUI
            },
            React,
            React: {
                useEffect,
                useRef,
                useState
            },
            ReactDOM: {
                render
            }
        } =
        window;

        const CONFIG = {
            CONFIG: {
                dots: 15,
                size: 1,
                text: 'Hey!',
                viewbox_width: 240,
                viewbox_height: 80
            },

            ANIMATION: {
                scale_speed: 1,
                scale_delay: 5,
                lighten_speed: 0.15,
                lighten_delay: 2
            },

            PROBABILITY: {
                scale: 0.85,
                lighten: 0.6
            }
        };



        const BOUNDS = {
            CONFIG: {
                dots: [2,
                    30],
                size: [0.1,
                    5,
                    0.1],
                viewbox_width: [0,
                    500,
                    1],
                viewbox_height: [0,
                    500,
                    1]
            },

            ANIMATION: {
                scale_speed: [0.1,
                    2,
                    0.01],
                scale_delay: [0,
                    10,
                    0.01],
                lighten_speed: [0.1,
                    2,
                    0.01],
                lighten_delay: [0,
                    10,
                    0.01]
            },

            PROBABILITY: {
                scale: [0,
                    1,
                    0.01],
                lighten: [0,
                    1,
                    0.01]
            }
        };



        const ANIMATE = (element, props, config) => {
            to(element, config.duration, {
                yoyo: true,
                repeat: 1,
                delay: `random(0, ${config.delay})`,
                onComplete: () => ANIMATE(element, props, config),
                ...props
            });

        };

        const App = () => {
            const [model,
                setModel] = useState(0);
            const datRef = useRef(null);
            const {
                size,
                dots,
                text,
                viewbox_width: width,
                viewbox_height: height
            } =
            CONFIG.CONFIG;
            useEffect(() => {
                if (!datRef.current) {
                    datRef.current = new GUI({
                        name: �.........完整代码请登录后点击上方下载按钮下载查看

网友评论0