In image above I have marked space that is occupied by my input field (which has hidden visibility).
What I want is to remove that space and only use it when user hit the
search icon
(my search icon
will come to the right side, next
to the user image)
Codes
html
<div id="searchbtn"><span class="fas fa-search"></span></div> //search icon
<form class="form-inline" action="/search" target="_blank" method="GET" role="search">
{{ csrf_field() }}
<div class="navfix">
<div id="navfix2">
<div id="search" class=" hide"> //search id
<div class="input-group-icon"> //input field
<input type="text" name="q" class="single-input" autocomplete="off" placeholder="Search in blog... 'type + enter' " required class="single-input">
<div id="searchremovebtn" class="icon"><i class="far fa-window-close"></i></div>
</div>
</div>
</div>
</div>
css
.hide{
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s linear;
}
.show{
visibility: visible;
opacity: 1;
transition: visibility 1s, opacity 1s linear;
}
.navfix {
position:relative;
margin-right: 0;
}
.navfix2 {
position:absolute;
}
jQuery
// search script
$(document).ready(function() {
var trig = 1;
//fix for chrome
$("#search").addClass('hide');
//animate searchbar width increase to +150%
$('#searchbtn').click(function(e) {
//handle other nav elements visibility here to avoid push down
$('#search').removeClass('hide');
$('#search').addClass('show');
$('#searchbtn').removeClass('show');
$('#searchbtn').addClass('hide');
if (trig == 1){
$('#navfix2').animate({
width: '+=150',
marginRight: 0
}, 100);
trig ++;
}
});
// if user leaves the form the width will go back to original state
$("#searchremovebtn").click(function() {
$('#navfix2').animate({
width: '-=150'
}, 100);
trig = trig - 1;
//handle other nav elements visibility first to avoid push down
$('#search').removeClass('show');
$('#search').addClass('hide');
$('#searchbtn').addClass('show');
$('#searchbtn').removeClass('hide');
});
});
</div>
</form>