Input框内的提示文字变化效果

大致效果如下:

点击前,灰色的placeholder的效果(其实不是写在placeholder里的)

点击后效果,变小 上移

 

代码如下:

Html:

(都是重复的这里就贴了其中一行的)

<div>
    <div class="floatText">手机号</div>
    <input id="mobileNum" class="inputBox" type="tel">
</div>

css:

.floatText {
    position: absolute;
    bottom: 9px;
    z-index: 9;
    pointer-events: none;
    font-size: 14px;
}

jQuery:

//输入框提示文字特效===================================
        $(".inputBox").focus(function () {
            var inputitems = $(".inputBox");
            var index = $(".inputBox").index(this);
            var oldBrother = $(inputitems[index]).prev();
            $(oldBrother).animate({
                bottom: '32px',
                fontSize: '12px',
            }, 300);
        });

        $(".inputBox").blur(function () {
            if ($(this).val() == "") {
                var inputitems = $(".inputBox");
                var index = $(".inputBox").index(this);
                var oldBrother = $(inputitems[index]).prev();
                $(oldBrother).animate({
                    bottom: '9px',
                    fontSize: '16px',
                }, 300);
            }
        });

思路很简单: 把div定位在input框里, 禁用它的鼠标事件,这样点击输入时就不会点着它, 然后输入框聚焦时,div内文字变小上移,失焦是恢复正常.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值