1
I am styling an input/search field using the onclick of javascript, I can do 50% but the rest I’m cracking my head and I don’t know what to do.
I was able to make the text input box to make the search appear only when I click the button.
But I need that by clicking again on the button or any other corner of the screen that was not in the search field, automatically the search field would hide again, do the same effect to display, but in reverse.
Ex search box:
Code:
$('#imagembusca').click( function() {
$("#busca").attr('style', 'width: 200px; transition: all 0.5s linear; border-radius: 0 20px 20px 0; padding:0 10px 0 30px;');
});
#btbusca{
max-width:250px;
height: 30px;
padding: 0;
}
#imagembusca{
background:#FF0004;
color: #FFFFFF;
border-radius: 20px;
width: 15px;
height: 15px;
padding: 7.5px 12px;
display: inline-block;
position: absolute;
z-index: 1;
}
#imagembusca:hover{
background: #B00002;
transition: all 0.5s linear;
}
#busca{
background:#EEE;
width: 0px;
line-height:30px;
display: inline-block;
position: absolute;
margin: 0 0 0 15px;
transition: all 0.5s linear;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="btbusca">
<img src="https://www.sccpre.cat/mypng/full/51-514569_dibujo-lupa-png-desenho-lupa-para-colorir.png" id="imagembusca" alt="buscar" />
<input type="search" name="busca" id="busca" placeholder="Buscar">
</div>
Perfect, exactly what I needed!
– Arthur74