1
Good afternoon, you guys!
I have the following problem: my input does an effect when it is selected (as shown in the first print) and ends the effect when it takes the focus from it (as shown in the second print), but if I put some character and focus, the text overwrites the content (as shown in the third print). There is a JS code that detects if you have something in the input not to do the effect, but it is not working. I would like a help if possible. The codes are below.
Html:
<div class="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");
}
})
});
This above JS code that should detect but is not working!
Actually, I can not avoid the JS, but since I do not know much in depth, I prefer to avoid. I get very lost with JS, I arise many doubts, various problems and is not ideal, since it is frustrating to see the work does not go forward.
– Giuseppe Nunes