我想对输入文本进行动画处理

时间:2019-07-19 10:33:42

标签: html css

我想对输入文本进行动画处理,当我在文本输入中键入内容时,必须显示具有动画效果的文本。

是否可以制作这种动画,如果可能,请提出建议。

我附上了样本ux

enter image description here

2 个答案:

答案 0 :(得分:1)

获得解决方案

  function pinpad(cur){
    $(cur).parent().addClass('addclass');
  }
.wrapper{
                width:320px;
                margin: 0px auto;
            }

        .ppWrapper {
        flex-direction: row;
        box-sizing: border-box;
        display: flex;
        place-content: center space-between;
        align-items: center;
    }
    .addclass {
        font-family: 'Material Icons';
        content: "";
        font-weight: 400;
        font-style: normal;
        font-size: 23px;
        line-height: 1;
        letter-spacing: normal;
        text-transform: none;
        display: inline-block;
        white-space: nowrap;
        word-wrap: normal;
        direction: ltr;
        -webkit-font-feature-settings: 'liga';
        -webkit-font-smoothing: antialiased;
    }
    .inputbox {
        display: inline-block;
        position: relative;
    }
    @-webkit-keyframes flying {
        0% {
          opacity: 0;
        }
    
        2% {
          opacity: 0;
          -webkit-transform: translateY(-30px);
        }
    
        5% {
          opacity: 1;
          -webkit-transform: translateY(0px);
        }
    
        17% {
          opacity: 1;
          -webkit-transform: translateY(0px);
        }
    
      }
    
      @-ms-keyframes flying {
        0% {
          opacity: 0;
        }
    
        2% {
          opacity: 0;
          -ms-transform: translateY(-20px);
        }
    
        5% {
          opacity: 1;
          -ms-transform: translateY(0px);
        }
    
        17% {
          opacity: 1;
          -ms-transform: translateY(0px);
        }
    
      }
    
      @keyframes flying {
        0% {
          opacity: 0;
        }
    
        2% {
          opacity: 0;
          -webkit-transform: translateY(-20px);
          transform: translateY(-20px);
        }
    
        5% {
          opacity: 1;
          -webkit-transform: translateY(0px);
          transform: translateY(0px);
        }
    
        17% {
          opacity: 1;
          -webkit-transform: translateY(0px);
          transform: translateY(0px);
        }
    
      }
    .inputboxvalue{
        height: 50px;
        width: 50px;
        border: 1px solid #ccc;
        font-size: 3em;
        text-align: center;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border-radius: 0;
    	    color: transparent;
    }
    .addclass::before {
         font-family: "Material Icons";
         content: "\E061";
         position: absolute;
         margin: auto;
         top: 0;
         right: 0;
         bottom: 0;
         left: 0px;
         text-align: center;
         color: black;
         width: 24px;
         height: 26px;
          -webkit-animation: flying 10s;
          -ms-animation: flying 10s;
          animation: flying 10s;
        } 
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="wrapper">
  <div  class="ppWrapper">
    <div  class="inputbox" >
      <input  class="inputboxvalue " type="password"  maxlength="1"  onkeydown="pinpad(this)">
    </div>
    <div  class="inputbox">
      <input  class="inputboxvalue "  type="password"  maxlength="1"  onkeydown="pinpad(this)">
    </div>
    <div  class="inputbox">
      <input  class="inputboxvalue "  type="password"  maxlength="1"  onkeydown="pinpad(this)">
    </div>
    <div  class="inputbox">
      <input  class="inputboxvalue " type="password"  maxlength="1"  onkeydown="pinpad(this)">
    </div>
  </div>
</div>

答案 1 :(得分:-1)

请尝试以下给出的代码。

HTML

<div class="input-field">
    <input type="text" id="name" required />
    <label for="name">Your name:</label>
</div>

CSS

.input-field {
  position: relative;
  width: 250px;
  height: 44px;
  line-height: 44px;
}
label {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  color: #d3d3d3;
  transition: 0.2s all;
  cursor: text;
}
input {
  width: 100%;
  border: 0;
  outline: 0;
  padding: 10px 0px 13px;
  border-bottom: 2px solid #d3d3d3;
  box-shadow: none;
  color: #111;
}
input:invalid {
  outline: 0;
}
input:focus,
input:valid {
  border-color: #00dd22;
}
input:focus~label,
input:valid~label {
  font-size: 14px;
  top: -24px;
  color: #00dd22;
}