找回密码
 立即注册
查看: 214|回复: 8

打字特效

[复制链接]

1

主题

2

回帖

26

积分

新手上路

积分
26
发表于 2022-9-13 19:07:40 | 显示全部楼层 |阅读模式

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient(to bottom, #6a85b6, #bac8e0);
            overflow: hidden;
        }
        h1 {
            color: #fff;
            text-align: center;
        }
        .input-box {
            position: relative;
        }
        .input-box input {
            opacity: 0;
        }
        .input-box label {
            min-width: 100%;
            min-height: 40px;
            background-color: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 5px;
            padding: 0 10px;
            cursor: text;
            transition: 0.2s;
        }
        .input-box input:focus~label {
            box-shadow: 0 5px 20px #6a85b6;
        }
        .input-box span {
            font-size: 16px;
            font-weight: bold;
        }
        .input-animate {
            animation: print 0.2s ease-in-out;
        }
        .shake {
            animation: shake 0.2s ease-in-out;
        }
        @keyframes print {
            0% {
                position: absolute;
                transform: scale(50);
            }
            99% {
                position: absolute;
            }
            100% {
                position: relative;
            }
        }
        @keyframes shake {
            50% {
                transform: scale(0.95);
            }
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div class="container">
        <h1>输入框打字特效</h1>
        <div class="input-box">
            <input type="text" id="txtMessage" v-model="message">
            <label for="txtMessage">
                <span class="input-animate" v-for="m in message2">
                    {{m}}
                </span>
            </label>
        </div>
    </div>
</body>
</html>
<script>
    new Vue({
        el: '.container',
        data: {
            message: ''
        },
        watch: {
            message: {
                handler: function (newVal, oldVal) {
                    if (newVal.length > oldVal.length) {
                        setTimeout(() => {
                            document.querySelector('.input-box').classList.
                                add('shake');
                            setTimeout(() => {
                                document.querySelector('.input-box').
                                    classList.remove('shake');
                            }, 300);
                        }, 200);
                    }
                }
            }
        },
        computed: {
            message2: function () {
                return this.message.split('');
            }
        }
    })
</script>




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

0

主题

1

回帖

20

积分

新手上路

积分
20
发表于 2022-9-13 19:08:40 | 显示全部楼层
真的帅 !!!
回复

使用道具 举报

0

主题

1

回帖

32

积分

新手上路

积分
32
发表于 2022-9-13 19:09:42 | 显示全部楼层
楼主牛皮
回复

使用道具 举报

0

主题

1

回帖

6

积分

新手上路

积分
6
发表于 2022-9-13 19:25:34 | 显示全部楼层
好腻害啊
回复

使用道具 举报

0

主题

1

回帖

32

积分

新手上路

积分
32
发表于 2022-9-13 19:34:50 | 显示全部楼层
好帅好帅,大佬带带
回复

使用道具 举报

0

主题

2

回帖

30

积分

新手上路

积分
30
发表于 2022-9-13 20:21:12 | 显示全部楼层
雀食蟀
回复

使用道具 举报

3

主题

7

回帖

243

积分

中级会员

积分
243
发表于 2022-9-14 10:37:00 | 显示全部楼层
哇塞,,,,看起来不错哎
回复

使用道具 举报

1

主题

1

回帖

34

积分

新手上路

积分
34
发表于 2022-9-14 10:39:08 | 显示全部楼层
666666666666
回复

使用道具 举报

1

主题

1

回帖

18

积分

新手上路

积分
18
发表于 2022-9-14 10:42:41 | 显示全部楼层
楼主666666啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|粤嵌技术交流空间

GMT+8, 2025-7-8 03:34 , Processed in 0.680677 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表