-
Notifications
You must be signed in to change notification settings - Fork 37
Laggy Animation with many fields #22
Copy link
Copy link
Open
Labels
Description
I found that the floating animation lags a lot when there are a lot going on in the same page. Because my app is designed to have many fields on it on the same page, and I'm using Angular which probably does a lot of checking and processing.
As a result, each time the page is loaded the animation is halted each time causing the label to overlap with the value in the inputs.
So, I did a little digging and found that the animation works a lot better with transform instead of changing the layout or size of the element directly.
Here's the fixed CSS code below. You might need to update the initial top attribute a bit, as I have another class that tells the size of my input boxes.
.has-float-label {
display: block;
position: relative;
}
.has-float-label label, .has-float-label > span {
position: absolute;
cursor: text;
font-size: 75%;
opacity: 1;
z-index: 3;
line-height: 1;
padding: 0 1px;
}
.has-float-label label::after, .has-float-label > span::after {
content: " ";
display: block;
position: absolute;
background: white;
height: 2px;
top: 50%;
left: -.2em;
right: -.2em;
z-index: -1;
}
.has-float-label .form-control::-webkit-input-placeholder {
opacity: 1;
-webkit-transition: all .2s;
transition: all .2s;
}
.has-float-label .form-control::-moz-placeholder {
opacity: 1;
transition: all .2s;
}
.has-float-label .form-control:-ms-input-placeholder {
opacity: 1;
transition: all .2s;
}
.has-float-label .form-control::placeholder {
opacity: 1;
-webkit-transition: all .2s;
transition: all .2s;
}
/* These rules are to hide the actual placeholder, when the input doesn't have value yet isn't focused on */
.has-float-label .form-control:placeholder-shown:not(:focus)::-webkit-input-placeholder {
opacity: 0;
}
.has-float-label .form-control:placeholder-shown:not(:focus)::-moz-placeholder {
opacity: 0;
}
.has-float-label .form-control:placeholder-shown:not(:focus):-ms-input-placeholder {
opacity: 0;
}
.has-float-label .form-control:placeholder-shown:not(:focus)::placeholder {
opacity: 0;
}
.has-float-label .form-control:placeholder-shown:not(:focus) + * {
font-size: 150%;
opacity: .5;
font-weight: normal;
top: .3em;
}
.input-group .has-float-label {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
margin-bottom: 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
.input-group .has-float-label .form-control {
width: 100%;
border-radius: 0.25rem;
}
.input-group .has-float-label:not(:last-child), .input-group .has-float-label:not(:last-child) .form-control {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
border-right: 0;
}
.input-group .has-float-label:not(:first-child), .input-group .has-float-label:not(:first-child) .form-control {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}
/* This is to set the starting point of the animation of the label */
.has-float-label .form-control + label {
top: 1.5em;
}
.it-dynamic-component .has-float-label .form-control:focus + label, .it-dynamic-component .has-float-label .form-control:not(:placeholder-shown) + label {
transform: translateY(-2.8em);
transition: transform .2s;
}
Reactions are currently unavailable