文本框动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .out {
            width: 320px;
            /*height: 200px;*/
            margin: 100px auto;
            position: relative;
            text-align: center;
        }

        .tips {
            width: 110px;
            height: 0;
            position: absolute;
            top: -25px;
            right: 0;
            font-size: 14px;
            color: #ffffff;
            background-color: #333333;
            border-radius: 3px;
            text-align: center;
        }
        input {
            width: 320px;
            height: 38px;
            font-size: 16px;
        }
        .user {
            font-size: 16px;
            position: absolute;
            top: 9px;
            left: 16px;
            padding: 0 2px;
            background-color: #ffffff;
            transition: all 0.5s;
            color: #aaa;
        }
    </style>
</head>
<body>
<form action="">
    <div class="out">
        <div class="user">用户名/手机号</div>
        <div class="tips">请输入登录账号</div>
        <input type="text" id="button">
    </div>
</form>
<script>
    document.getElementById('button').onfocus = function () {
        var h = 0;
        var timer = setInterval(function () {
            h += 2;
            document.getElementsByClassName('tips')[0].style.height = h + 'px';
            if (h > 20) {
                clearInterval(timer);
            }
        }, 10);
        document.getElementsByClassName('user')[0].style.transform = 'scale(0.7) translate(-25px,-29px)';
        document.getElementsByClassName('user')[0].style.color = 'deepskyblue';
    };
    document.getElementById('button').onblur = function () {
        var h = parseInt(document.getElementsByClassName('tips')[0].style.height);
        var timer = setInterval(function () {
            h -= 2;
            document.getElementsByClassName('tips')[0].style.height = h + 'px';
            if (h < 0) {
                clearInterval(timer);
            }
        }, 10);
        document.getElementsByClassName('user')[0].style.transform = 'none';
        document.getElementsByClassName('user')[0].style.color = '#aaa';
    }
//    事件方法
    document.getElementsByClassName('user')[0].οnclick=function () {
        document.getElementsByTagName('input')[0].focus();
    }
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值