Really easy question here. I did some searching and nothing obvious returned. I am creating a quick search box for my site. I got it so that it expands out and collapses as expected. However, what I want to do is also hide it whenever i lose focus of the container altogether. That way it is not taking up space when the user clicks somewhere else on the site.
Behold the search in top right. When you click the search, it pops out. However, the only way to roll it back in is to click the search again. What happens when the user clicks away to the site? The search is still out there. I would like to retract the search when the user places their attention elsewhere in the site.
I dont have a perfect solution. Maybe there is someone out there who has better skills than me.
But for the basics, its just something like this that you ll need to copy/paste in your “custom code body field”:
Give your search form a unique ID.
Then paste this code:
(dont forget to include the script tags)
You ll need to change the numbers here in order to get a good result. (150px is just an example).
Then also dont forget to go to your SEARCH FORMFIELD Element in Webflow Designer and choose a
“Effect → Transition” e.g.
If you search form closing by interaction, you can try to apply same interaction to the body. So if user click on the body it will close search form. But in this case I am afraid, that it will be hard to actually type inside the form.
The Effect → Transition will add a css property to the element with that #ID.
And the script searches an element with that specific id and adds a transform movement (x-axis) when its clicked.
Since you then already have a transition added via the css styling on that element, it will run smoothly :).