input表單輸入框聚焦動畫特效

在這裏插入圖片描述

表單動畫1

html源碼

<div class="inputBox">
    <input class="effect-1" type="text" placeholder="Placeholder Text">
    <span class="focus-border">
        <i></i>
    </span>
</div>

css源碼

inputBox class類用於佈局,就是一個input容器,便於觀看,我這裏設置每一行分爲3個列(可根據本身需求設置)。css

.inputBox {
      float: left;
      width: 27.33%;
      margin: 40px 3%;
      position: relative; 
}

而後爲input元素設置一些通用樣式。html

input[type="text"]{
    font: 15px/24px "Lato", Arial, sans-serif; 
    color: #333; 
    width: 100%; 
    box-sizing: border-box; 
    letter-spacing: 1px;
}    
:focus{
    outline: none;
}

effect-1 class類就表明這不一樣的input表單獲取焦點的動畫樣式種類, effect-1就表明第一種,以此類推。佈局

.effect-1{
    border: 1px solid #ccc; 
    padding: 7px 14px 9px; 
    transition: 0.4s;
}
.effect-1 ~ .focus-border:before,
.effect-1 ~ .focus-border:after{
    content: ""; 
    position: absolute; 
    top: 0; 
    right: 0; 
    width: 0; 
    height: 2px; 
    background-color: #3399FF; 
    transition: 0.2s; 
    transition-delay: 0.2s;
}
.effect-1 ~ .focus-border:after{
    top: auto; 
    bottom: 0; 
    right: auto; 
    left: 0; 
    transition-delay: 0.6s;
}
.effect-1 ~ .focus-border i:before,
.effect-1 ~ .focus-border i:after{
    content: ""; 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 2px; 
    height: 0; 
    background-color: #3399FF; 
    transition: 0.2s;
}
.effect-1 ~ .focus-border i:after{
    left: auto; 
    right: 0; 
    top: auto; 
    bottom: 0; 
    transition-delay: 0.4s;
}
.effect-1:focus ~ .focus-border:before,
.effect-1:focus ~ .focus-border:after{
    width: 100%; 
    transition: 0.2s; 
    transition-delay: 0.6s;
}
.effect-1:focus ~ .focus-border:after{
    transition-delay: 0.2s;
}
.effect-1:focus ~ .focus-border i:before,
.effect-1:focus ~ .focus-border i:after{
    height: 100%; 
    transition: 0.2s;
}
.effect-1:focus ~ .focus-border i:after{
    transition-delay: 0.4s;
}

在這裏插入圖片描述

表單動畫2

html源碼

<div class="inputBox">
    <input class="effect-2" type="text" placeholder="Placeholder Text">
    <span class="focus-border">
        <i></i>
    </span>
</div>

css源碼

.effect-2{
    border: 1px solid #ccc; 
    padding: 7px 14px 9px; 
    transition: 0.4s;
}
.effect-2 ~ .focus-border:before,
.effect-2 ~ .focus-border:after{
    content: ""; 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 0; 
    height: 2px; 
    background-color: #3399FF; 
    transition: 0.3s;
}
.effect-2 ~ .focus-border:after{
    top: auto; 
    bottom: 0; 
    left: auto; 
    right: 0;
}
.effect-2 ~ .focus-border i:before,
.effect-2 ~ .focus-border i:after{
    content: ""; 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 2px; 
    height: 0; 
    background-color: #3399FF; 
    transition: 0.4s;
}
.effect-2 ~ .focus-border i:after{
    left: auto; 
    right: 0; 
    top: auto; 
    bottom: 0;
}
.effect-2:focus ~ .focus-border:before,
.effect-2:focus ~ .focus-border:after{
    width: 100%; 
    transition: 0.3s;
}
.effect-2:focus ~ .focus-border i:before,
.effect-2:focus ~ .focus-border i:after{
    height: 100%; 
    transition: 0.4s;
}

在這裏插入圖片描述

表單動畫3

html源碼

<div class="inputBox">
    <input class="effect-3" type="text" placeholder="Placeholder Text">
    <span class="focus-border">
        <i></i>
    </span>
</div>

css源碼

.effect-3{
    border: 1px solid #ccc; 
    padding: 7px 14px 9px; 
    transition: 0.4s;
}
.effect-7 ~ .focus-border:before,
.effect-7 ~ .focus-border:after{
    content: ""; 
    position: absolute; 
    top: 0; 
    left: 50%; 
    width: 0; 
    height: 2px; 
    background-color: #3399FF; 
    transition: 0.4s;
}
.effect-7 ~ .focus-border:after{
    top: auto; 
    bottom: 0;
}
.effect-7 ~ .focus-border i:before,
.effect-7 ~ .focus-border i:after{
    content: ""; 
    position: absolute; 
    top: 50%; 
    left: 0; 
    width: 2px; 
    height: 0; 
    background-color: #3399FF; 
    transition: 0.6s;
}
.effect-7 ~ .focus-border i:after{
    left: auto; 
    right: 0;
}
.effect-7:focus ~ .focus-border:before,
.effect-7:focus ~ .focus-border:after{
    left: 0; 
    width: 100%; 
    transition: 0.4s;
}
.effect-7:focus ~ .focus-border i:before,
.effect-7:focus ~ .focus-border i:after{
    top: 0; 
    height: 100%; 
    transition: 0.6s;
}

搬你想搬,蓋你所需,碼字不易,且行且珍惜!動畫

相關文章
相關標籤/搜索