juliya
2/1/2018 - 9:35 AM

label animation on focus

.form-group {
    position: relative;
    margin-bottom: 15px;
    padding-top: 20px;
}
.form-control {
    display: block;
    .box-sizing();
    border: none;
    border-bottom: 1px solid #c2c1c7;
    padding: 0 0 9px;
    width: 100%;
    height: 30px;
    font-size: 16px;
    line-height: 1;
    font-family: @font;
    color: @text-color;
    background-color: #ffffff;
    .transition();
    &::-webkit-input-placeholder {
        font-size: 16px;
        font-family: @font;
        color: fade(@text-color, 50%);
        .transition();
    }
    &::-moz-placeholder {
        font-size: 16px;
        font-family: @font;
        color: fade(@text-color, 50%);
        .transition();
    }
    &:-moz-placeholder {
        font-size: 16px;
        font-family: @font;
        color: fade(@text-color, 50%);
        .transition();
    }
    &:-ms-input-placeholder {
        font-size: 16px;
        font-family: @font;
        color: fade(@text-color, 50%);
        .transition();
    }
    &:hover {
        background-color: #e2e1f1;
    }
    &:focus {
        color: @text-color;
        &::-webkit-input-placeholder {
            opacity: 0;
        }
        &::-moz-placeholder {
            opacity: 0;
        }
        &:-moz-placeholder {
            opacity: 0;
        }
        &:-ms-input-placeholder {
            opacity: 0;
        }
    }
}
.label {
    position: absolute;
    left: 0;
    top: 20px;
    font-size: 16px;
    font-family: @font;
    &.focus {
        top: 0;
        font-size: 12px;
        color: fade(@text-color, 50%);
    }
}
$(document).on('focus', '.form-control', function () {
        $(this).parent('.form-group').find('label').addClass('focus');
    });
    $(document).on('blur', '.form-control', function () {
        var value = $(this).val();
        if (value === '') {
            $(this).parent('.form-group').find('label').removeClass('focus');
        }
    });
<div class="form-group">
        <label class="label control-label label-required" for="name">Your name</label>
        <input id="name" class="form-control" type="text" name="name" required>
    </div>