Activity › Forums › Adobe After Effects Expressions › **Search Bar Text expression**
-
**Search Bar Text expression**
Posted by Ian Cross on July 4, 2020 at 7:34 amHi People,
So, I am trying to make an expression for text to resemble a search bar animation.
Similar to a ‘typewriter’ or ‘wordprocessor’ expression, except when it reaches a certain point in the text, the text starts to scrolls left as each letter appears.
Make sense?
IanFilip Vandueren replied 6 years, 1 month ago 2 Members · 3 Replies -
3 Replies
-
Filip Vandueren
July 4, 2020 at 12:26 pmOk, for starters; the animation you use for the type-on effect has to actually affect the size of the layer.
In other words: just using opacity to hide the letters won’t work: you need to set the scale of the invisible letters to [0,0].Depending on how you set up your animator, you might now see undesireable scaling up letters.
To combat that first: as the Range Selector’s units use “Index”, not percentage.
To the parameters you’ve animated for the scale animation (could be range Start, End, and/or Offset depending on your setup) add this expression:
Math.floor(value);
OK, that will make sure no letters are animated fractionally: they will be either selected, or not, they will be invisible (scale 0) or not, nothing inbetween, so no funky scaling.Thanks to these preceeding steps, we can make use of sourceRectAtTime(), to find the text’s current width/height.
give the text-layer’s anchorpoint this expression:
w=sourceRectAtTime().width;
max_w=400;
x=Math.max(0,w-max_w);
value+[x,0];
max_w would be the size in pixels of the box you want this to fit in.Make sure to add a box of that size on top of the text to act as an Alpha trackmatte, so the characters that move off the left side get masked.
You might notice that on spaces, the text does not scoot 1 character to the left.
Indeed: Spaces don’t add anything to the width.
A work-around could be to add dashes (or other characters that have the same width as a space) instead. If the background of your searchbox is a solid color, you can set the dashes to be that background color.
If that’s a problem because of other design choices, you can use baseline-shift on the dashes to move them up and out of view. They will still add to the width, but they’ll be masked of by the trackmatte… -
Ian Cross
July 4, 2020 at 4:42 pmThanks Filip for your reply.
Much appreciated.
Ive added the typewrite behaviour to that text layer, and added the expression you supplied to the anchor point of the text layer, whilst amending the number of the box width in pixels. But the text doesnt shift left at any point? -
Filip Vandueren
July 4, 2020 at 4:51 pmDoes it give an error ?
What do you see as value for anchorPoint ?If you enable “View -> Show Layer Controls”, then do you see the bounding Box of the string growing as the text is revealed ?
Reply to this Discussion! Login or Sign Up