Skip to main content

Animating with Opacity in jQuery Animate

By Sam Deering

JavaScript

Share:

😳 Ever felt a little embarassed sharing your JavaScript? Let's fix it.

When using opacity to fade in or fade out over time using jQuery.animate, you’ll run into font rendering issues with all versions of Internet Explorer.

This leaves you with 2 options:

Use jQuery’s opacity(‘show’) or opacity(‘hide’) shortcut properties which handle IE’s shortcomings, or Set the filter css property to ‘none’ once you’ve completed your animation Obviously, if you’re fading something in from being completely hidden, option 1 makes sense, otherwise you’ve got no choice but to use option 2.

I came across this as I had font rendering issues for Cruiseabout in tabs content that was being caused by my use of opacity in FCL.TABS. As a result, I’ve patched FCL.TABS to use opacity’s “show” and “hide” properties instead of “0? and “1? and the problem has been fixed.

Broken code

$tabContent.css('opacity', 0);
$tabContent.animate(
{
opacity: 1
}, 350);

Fixed code

$tabContent.css('opacity', 'hide');
$tabContent.animate(
{
opacity: 'show'
}, 350);

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

New books out now!

💁‍♀️ Fun Fact: Python was ranked #2 on a recent highest paid coders list. *


🤓 Ok. When did a code editor from Microsoft become kinda cool!?