Pricing Blog

Animating a sidebar

  • tomthebigtree-1180873229708050542

    Tom Ireland

    2 years ago

    Hey, folks. Can anyone provide any advice on animating a sidebar? I'm trying to have a right-hand sidebar slide in from the right like a drawer but no matter what I do, I cannot seem to get it to work. The sidebar is in a div and has a show/hide formula applied based on button click event. Any pointers?
  • andreasmoller-1180875461203595386

    Andreas Møller

    2 years ago

    The Simplet way is to always have it shown, but move it off screen with a transform
  • The have a class “open” the moves it back in
  • lucasg-1180914762897444944

    Lucas G

    2 years ago

    Either that or set width to 0
  • tomthebigtree-1180919331719233536

    Tom Ireland

    2 years ago

    Thanks, gents. I did manage to work with both width and transform (either will work) but still not able to get the transition to work.
  • I set it on background as a test, which worked, but width doesn't do anything.
  • I'm likely doing it wrong 💯
  • gazinhio-1180984592832921620

    gazinhio

    2 years ago

    I dunno if this helps, I did a video on recreating Bubble's floating groups in Toddle and I covered animating the side bar. It was a while ago and there might be easier ways now (not been Toddling much the last month or so) but worth seeing if it covers what you're looking for.

    https://youtu.be/GzAhzO522UM?si=_7JbdL6xn6E8y1Pb
  • tomthebigtree-1181132572491784212

    Tom Ireland

    2 years ago

    Nice one, @Andreas Møller . Thanks for putting that together and for setting up transform as a transition property/attribute. Managed to get it to work (kinda). My problem is that it's a right-hand sidebar, so it's add a scroll bar. I managed to sort that by adding overflow-x: hidden to the root div but still messes up container alignment. Moved it to the left-hand side, which is better but still got to figure out alignment as it's not removed from the flow when translating it seems, so all the width, margin, etc., remains in place, which affects the visible container. Fun times! 😄
  • Everything is positioned relative as opposed to absolute.
  • andreasmoller-1181132815929180180

    Andreas Møller

    2 years ago

    You want the menu to be positioned absolute
  • tomthebigtree-1181133135677755392

    Tom Ireland

    2 years ago

    Aye, but then it doesn't push the visible div aside to the right. Or would I need to position that one absolute as well?
  • That answer appears to be "yes"?!
  • andreasmoller-1181133375336091708

    Andreas Møller

    2 years ago

    Ah so you want it to move the main content?
  • tomthebigtree-1181133402099945513

    Tom Ireland

    2 years ago

    Indeed.
  • andreasmoller-1181134190155149323

    Andreas Møller

    2 years ago

    Ok you can animate padding -left on the main content at the same time
  • andreasmoller-1181134555273506866

    Andreas Møller

    2 years ago

    One thing to remember is that this transition is significantly slower, since the browser will need to re calculate the page layout over and over again
  • So if you are building a scrolling website with a lot of content this might be an issue
  • tomthebigtree-1181175922632708196

    Tom Ireland

    2 years ago

    Thanks for the tips. Will give that a go and see how I get on. Nah, not lots of scrolling content, so should be okay in this case. 🤞 👍
  • tomthebigtree-1181211686645026866

    Tom Ireland

    2 years ago

    Thanks, mate. This also helped. I did end up trying width as well, which works. In the end, I opted for animation on max-width as I couldn't figure out how to cleanly address the space left with transform on translate. Looks smooth, aside from application of padding on display. Shame there's no visibility animation. Been trying to reverse-engineer Todoist's sidebar and they seem to be doing something with visibility.
  • tomthebigtree-1181219004522704917

    Tom Ireland

    2 years ago

    Nailed it I think. Using max-width as the animation on the main sidebar div, I set a child container div to have the padding and have a show/hide set. This means that padding is not applied during the transition and makes the transition look smooth and also ensures child elements are not visible when reducing the width (I hadn't noticed this until there was stuff in the sidebar. This worked but you could see elements being "drawn" when showing the sidebar due to the max-width transition, so I set another show/hide on the div containing the elements based and set a sleep action on button click to half the transition time after the sidebar variable is set. This means the elements don't appear to be drawn and ease in/out with the transition. Unnecessarily complicated because I could not figure out the translate gap. 😄
    🔥2
  • tomthebigtree-1181220336449093783

    Tom Ireland

    2 years ago

    Here's a quick clip. Appreciate all the help, gents! 🙂