I am not the best with jQuery.
So wanted to add easing to this function:
$(function() {
$('#usergroup').change(function(){
$('.groups').hide();
$('#' + $(this).val()).show();
});
});
aside from adding (“slow”) to .show func and (1000) to .hide func.
Wondered what I would do to add swing , etc
Go for this plugin: http://jquery.malsup.com/cycle/ Or else, if you want more flexibility, read about jQuery animate: http://api.jquery.com/animate/
I use jQuery animate for almost all my needs.
You can also do transitions with CSS, but it’s not recommended. The options are very few and it’s not compatible across browsers.
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
My personal opinion, no one should be using jQuery for animating anymore. It’s insanely slow compared to modern animation libraries.
As for your question, “swing” is the default easing. But “show()” and “hide()” require an argument to animate. So you could do it like this:
$('.groups').hide("swing"); // default duration
or
$('.groups').hide(1000); // 1 second
- Exclusive Author
- Item was Featured
- Author was Featured
- Author had a File in an Envato Bundle
- Has been a member for 4-5 years
- Sold between 100 000 and 250 000 dollars
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- India
CodingJack said
My personal opinion, no one should be using jQuery for animating anymore. It’s insanely slow compared to modern animation libraries.
+1, personally I came to that extent too 
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
VF said
CodingJack said+1, personally I came to that extent too
My personal opinion, no one should be using jQuery for animating anymore. It’s insanely slow compared to modern animation libraries.![]()
Yeah, and I don’t want to sound like an elitist or anything. It’s just kind of like using fl.transitions back in the day vs. anything else.
- Exclusive Author
- Item was Featured
- Author was Featured
- Author had a File in an Envato Bundle
- Has been a member for 4-5 years
- Sold between 100 000 and 250 000 dollars
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- India
^ Yes, and as of now the Sizzle + javascript + stylesheet can be much flexible for light weight to complex animations (and cover wider devices), since we can’t depend on jQuery 2.0 anymore as it lacks supporting old IE versions.
CodingJack said
My personal opinion, no one should be using jQuery for animating anymore. It’s insanely slow compared to modern animation libraries.As for your question, “swing” is the default easing. But “show()” and “hide()” require an argument to animate. So you could do it like this:
$('.groups').hide("swing"); // default durationor
$('.groups').hide(1000); // 1 second
Interesting. I thought jQuery would have sufficed for simple animation needs. I wasn’t aware of this. What other libraries would you recommend for simple animation needs like, say, easing?
To be honest, we use jQuery natively throughout the site, so no need to use another library. I went with my initial code in the end, but used fast for show dec’ and 1000 for hide dec’ works a treat
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
nCrafts said
Interesting. I thought jQuery would have sufficed for simple animation needs. I wasn’t aware of this. What other libraries would you recommend for simple animation needs like, say, easing?
Depends on the application I guess. Personally, if I were just animating a few things I’d probably just use CSS3 and use jQuery as a fallback. But if you’re doing anything advanced and performance is important, you’ve really got to be using requestAnimationFrame (RAF), CSS3, or both. And as of right now, jQuery doesn’t support RAF.
Here’s a stress test that shows how miserable jQuery performs compared to two other animation engines:
http://www.codingjack.com/playground/jacked/jquery.htmlAnd in that test jQuery isn’t animating color while the other two are so even with an extra layer of animation removed it’s still that bad.
