Good afternoon, guys!
I have the following problem: my input has an effect when it is selected (as the first print shows) and ends the effect when it takes focus from it (as the second print shows), but if I put some character and focus, the text overlaps the content (as shown in the third print). It has a JS code that detects if it has something in the input to not make the effect, but it is not working. I would like some help if possible. The codes are below.
Html:
<divclass="col-3 input-effect">
<i class="fa fa-lock" aria-hidden="true"></i>
<input type="password" class="effect" placeholder="" name="senha" required>
<h3>Insira sua senha</h3>
<span class="focus-border"></span>
</div>
CSS:
.effect{
position: relative;
background-color: transparent;
}
.effect ~ .focus-border{
position: absolute;
margin-left: 49.4px;
bottom: 0; left: 50%;
width: 0;
height: 2px;
background-color: #4CAF50;
transition: 0.4s;
z-index: 2;
}
.effect:focus ~ .focus-border,
.has-content.effect ~ .focus-border{
width: 80%; transition: 0.4s; left: 0;
}
.effect ~ h3{
position: absolute; margin-left: 48px; width: 100%; top: 8px; color: #aaa; transition: 0.3s; letter-spacing: 0.5px; cursor: default;
}
.effect:focus ~ h3, .has-content.effect ~ h3{
top: -16px; font-size: 12px; color: #4CAF50; transition: 0.3s;
}
JS:
$(window).load(function(){
$(".col-3 input").val("");'
$(".input-effect input").focusout(function(){
if($(this).val() != ""){
$(this).addClass("has-content");
}else{
$(this).removeClass("has-content");
}
})
});
That JS code above should detect, but it is not working!