Share Posted February 1, 2019 Can anyone give me some pointers for making the show/hide animation smooth? I wanted something that could replace jQuery's show/hide with a "blind" effect. The element I'm working with is centered using margin: 0px auto; and I can't be sure of the final height. So basically I'd like to animate from visible down to height/margin/padding 0, and invisible up to height auto (margin/padding being whatever they might have been previously). To do so I made a .GSAPHideMe_CenteredElement class that I toggle, which has properties for height / margin etc. The "hide" version of the tween should animate to those settings, then assign the class to the object and clear the settings. The "show" version pretty much just removes the class. This all works, but it's choppy.. Is there a better way to go about it? See the Pen pGPJOG by anon (@anon) on CodePen Link to comment Share on other sites More sharing options...
Share Posted February 1, 2019 Hi @MikeWillis, My suggestion would be to break the animation down into parts to find out what part of the code is causing it to be choppy. I wasn't able to easily read enough of what's happening in your code, to give a direct suggestion. I think you may be better of using a play() / reverse() on toggle the show hide too, for simplicity sake (see this nav toggle I built a while back See the Pen Vezxxy?editors=1010 by ryan_labar (@ryan_labar) on CodePen ). 4 Link to comment Share on other sites More sharing options...
Share Posted February 2, 2019 On 2/1/2019 at 3:37 PM, MikeWillis said: This all works, but it's choppy.. Is there a better way to go about it? Sure. Don't animate all the things... #banner-message { background: #fff; border-radius: 4px; padding: 20px; font-size: 25px; text-align: center; /* transition: all 0.2s; */ margin: 0 auto; width: 75%; } CSS and JS can't animate the same properties. If you need CSS transitions on an element you're animating with JS, you should explicitly list those properties. Using "all" can also impact performance because the browser has to watch for changes to all those properties. Also, there's no such thing as an int or float type in JavaScript. Only "number". if ( arguments.length >= 5 && (typeof(speed) == "float" || typeof(speed) == "int") ) { Settings.speed = speed; } 6 1 Link to comment Share on other sites More sharing options...
Author Share Posted February 4, 2019 On 2/1/2019 at 8:12 PM, OSUblake said: #banner-message { background: #fff; border-radius: 4px; padding: 20px; font-size: 25px; text-align: center; /* transition: all 0.2s; */ margin: 0 auto; width: 75%; } PERFECT - animation is completely smooth now! What a difference! On 2/1/2019 at 8:12 PM, OSUblake said: Also, there's no such thing as an int or float type in JavaScript. Only "number". Duh - good point - too much PHP that day! thanks OSUblake! 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now