I'm working on a project called CodeSlider, which is currently live. The app animates the difference between two code editors: removed elements fade away, added elements fade in, and moved or unchanged elements animate positions. I'm currently using Remotion and handing the movement animations with changes to an element's opacity and top and left absolute positioning. Overall, things are working great, but there's a bug that I need help to figure out.
The bug occurs when a piece of code is long and needs to wrap to the following line. Everything looks fine in the editor because it's not using absolute positioning, but things get wonky when I try to animate the changes. So, it got me thinking: could GSAP help me solve this issue?
For context, my app uses Prism to chunk the code snippets into sections and then figures out the difference between the sections in two sequential slides using a diffing algorithm. Below is a very basic example of what's returned from the diffing algorithm:
[
{
"content": "const",
"aIndex": 0,
"bIndex": 0
},
{
"content": " test ",
"aIndex": 1,
"bIndex": -1
},
{
"content": " hello ",
"aIndex": -1,
"bIndex": 1
},
{
"content": "=",
"aIndex": 2,
"bIndex": 2
},
{
"content": " ",
"aIndex": 3,
"bIndex": 3
},
{
"content": "\"\"",
"aIndex": 4,
"bIndex": -1
},
{
"content": "\"World\"",
"aIndex": -1,
"bIndex": 4
}
]
The "content" represents the content of the code block, the "aIndex" represents the position of the element at the start, and the "bIndex" represents the position of the element at the end. If the value is "-1" for the "aIndex," that means the value was not present at the start, and if it was "-1" for the "bIndex," that means it was not present at the end. So, with this info, we can decipher the following: what blocks were added, what blocks were moved, and then the remaining blocks (some that don't move and some that do).
So, can GSAP handle animating these code blocks without using absolute positioning? Right now, I'm doing a bunch of calculations to figure out where to put items, which is why it gets complicated when lines are much longer, such as importing a long line of CSS for a Google Font. It would be awesome to let GSAP do the heavy lifting for me and not have to worry about all the weird quirks that come with absolute positioning. 😅
Thank you, and I'm looking forward to seeing how GSAP can help!