自制input样式(动画)

我目前只模仿了一种,后期右的话还会继续加进来的。

  1. 有动画效果的,截屏看不出来
    在这里插入图片描述
    在这里插入图片描述
    HTML:
<div class="input-group">
     <input class="input__field" type="text" id="input-1"  onblur="inputBlur(this)"/>
      <label class="input__label" for="input-1">
          <span class="input__label-content input__label-content--nao">载波(MHz)</span>
      </label>
</div>

CSS:

.input-group{
    width: 43%;
    display: inline-block;
    margin: 20px 40px 0 0;
    position: relative;
    height: 50px;
    padding-top: 16px;
}

.input__field {
    width: 100%;
    position: relative;
    display: block;
    border: none;
    border-bottom: 2px solid #9da8b2;
    border-radius: 0;
    padding: 0.5em 0em 0.25em;
    background: transparent;
    color: #9da8b2;
    font-size: 1.25em;
    font-weight: 400;
    font-family: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
    -webkit-appearance: none;
}

.input__field:focus,
.imitationSelect:focus,
.btn-calculate:focus{
    outline: none;
}

.input__label {
    display: block;
    width: 100%;
    color: #797979;
    font-size: 1.2rem;
    position: absolute;
    top: 0;
    left: 0;
    text-align: left;
    pointer-events: none;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    -webkit-transition: -webkit-transform 0.2s 0.15s, color 1s;
    transition: transform 0.2s 0.15s, color 1s;
    -webkit-transition-timing-function: ease-out;
    transition-timing-function: ease-out;
}

.input__label-content {
    position: relative;
    display: block;
    padding: 1.6em 0;
    width: 100%;
}

.input__field:focus + .input__label{
    color: #252525;
    -webkit-transform: translate3d(0, -1.25em, 0) scale3d(0.75, 0.75, 1);
    transform: translate3d(0, -1.25em, 0) scale3d(0.75, 0.75, 1);
}

.has-value{
    transform: translate3d(0, -1.25em, 0) scale3d(0.75, 0.75, 1);
}

JS:

function inputBlur(e) {
    if ($(e).val() === "") {
        $(e).parent().removeClass("input--field");
        $(e).next().removeClass("has-value");
    } else {
        console.log($(e).val());
        $(e).next().addClass("has-value");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值