It seems like you're looking to create an animation for the input field where it expands gradually, like this:
|[button]
|<--|[button]
|<----|[button]
|<-------|[button]
Instead of simply shifting the button as follows:
|[button]
-->|[button]
---->|[button]
To achieve this effect, you need to adjust both the width and left positioning of the input element. Currently, the animate function is only changing the width without moving the input's starting position. Therefore, you also need to shift the button along with the input to accommodate its increased width.
To implement this behavior, you can modify the code as shown below:
$('#btn-search').on('click', function(e) {
e.preventDefault();
$('#search').animate({
width: 'toggle',
left: "-=177", // Adjust based on the input element's width
}).focus();
$('#btn-search').animate({left: "-=177"});
});
Keep in mind that there may be additional adjustments required when following this approach. For a more comprehensive guide, check out this article on managing the button and input element using different JavaScript and CSS techniques: http://tympanus.net/codrops/2013/06/26/expanding-search-bar-deconstructed/