Vor Kurzem aufgerufene Suchen
Keine vor kurzem aufgerufene Suchen
Typing animation / typewriter effect for placeholder of homepage search bar
Gepostet 02. Jan. 2024
What we wanted to achieve: When users land on our zendesk homepage the focus should lie on the search field. Sometimes you do not exactly know what you can search for. In our searchbar we wanted users to get suggestions for useful search questions. To make it extra fancy those suggestions should have a typewriter effect to appear as being typed out in real time.
What you need: a little bit of time and ideally dynamic content enabled, but you could also hardcode the placeholders if you don't use multi language support.
How to do it: If you want to use dynamic content for the placeholders, you should create those first (Admin Center -> Agent Tools -> Dynamic Content).
We created three different placeholders and named them search placeholder 1/2/3 so we can use them with the dynamic content helper like
{{dc 'search_placeholder_1')
If you are not using dynamic content you can skip step 1.
1.
In your document_head.hbs add the following lines after the first <meta> tag:
<meta name="search-placeholder-one" content="{{dc 'search_placeholder_1'}}" />
<meta name="search-placeholder-two" content="{{dc 'search_placeholder_2'}}" />
<meta name="search-placeholder-three" content="{{dc 'search_placeholder_3'}}" />
2. Now for the cool stuff add the following lines at the end of your script.js file: window.addEventListener("load", () => { Again, if you do not use dynamic content you can delete this part const placeholderElements = [ and just use hardcoded strings as placeholders instead: const placeholders = [ |
||
And that's it. Check your live preview and see the magic happen :) | ||
3
4 Kommentare
Brett Bowser
0
Matt Farrington Smith
This is very cool - thank you for sharing Nico Bruning!
I presume it's based on the TypeIt functionality? I can't work out a way to control the speed though, any pointers?
1
Nico Bruning
Matt Farrington Smith cool that you like it.
The basic idea came from this: https://codepen.io/leetech/pen/dOOgBx
If you want to change the speed, look for the
function. The second parameter is the time in Milliseconds.
You could introduce a const for the typing speed like
just at the top, where the other consts are introduced and then change the function to
This way you can change the speed from a central place and you and your colleagues can improve the readability.
Hope this helps.
0
Matt Farrington Smith
Amazing! Thank you so much Nico :-) That did exactly what I wanted it too.
0