views:

5352

answers:

9

I have a simple unordered list that I want to show and hide on click using the jQuery slideUp and slideDown effect. Everything seems to work fine, however in IE6 the list will slide up, flicker for a split second, and then disappear.

Does anyone know of a fix for this?

Thanks!

+7  A: 
$(document).ready(function() {
    // Fix background image caching problem
    if (jQuery.browser.msie) {
        try { 
            document.execCommand("BackgroundImageCache", false, true); 
        } catch(err) {}
    }
};

Apparently.

Oli
You can bin the if-statement but that might hit the performance ever-so-slightly on non-IE6 browsers because they'll try to execute the code (and fail).
Oli
This is really helpful info, unfortunately it doesn't fix the issue that I'm having... I added the code and my list is still flickering.
go minimal
I wish I would have found this first, because it fixed my problem in ie6. Thanks
Kevin
Holy crap, this is brilliant! That flickering has been bothering me for years!
Olly Hodgson
+7  A: 

Just let IE6 flicker. I don't think it's worth it to invest time in a dying browser when your base functionality works well enough. If you're worried about flickering for accessibility reasons, just sniff for IE6 and replace the animation with a generic show() and hide() instead. I recommend avoiding complicated code for edge cases that don't matter.

Ryan McGeary
+1 as I agree in principle. Though in practice I will point out that's not 100% doable yet. Many enterprises (including my employer) require grade-A support on IE6. Depends on the audience, though thankfully that audience is shrinking.
Rex M
I'm in the same boat regarding my company. Well over 3/4 of the company uses ie6.
Kevin
If 75% of your company still uses IE6, maybe it's time to either reconsider your career or to just stop offering animation niceties.
Ryan McGeary
+2  A: 

Oli's fix only seems to apply to flickering backgrounds, which is not the case here.

Ryan McGeary's advice is solid, except for when the client/your boss absolutely demand that IE6 not act like it has fetal alcohol syndrome.

I found the solution here: Slide effect bugs in IE 6 and 7 since version 1.1.3

Added a doctype declaration to the top of the file (why wasn't it there before? who knows!) and the flicker vanished, never to be seen again.

Pavel Lishin
+11  A: 

Apologies for the extra comment (I can't upvote or comment on Pavel's answer), but adding a DOCTYPE fixed this issue for me, and the slideUp/Down/Toggle effects now work correctly in IE7.

See A List Apart for more information on DOCTYPES, or you can try specifying the fairly lenient 4/Transitional:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
Mike Gardiner
Thanks so much! Works great now. Good 'ole StackOverflow. :-)
Ducain
Amazing how a DOCTYPE can make such a huge difference
MunkiPhD
+1  A: 

I posted a quick fix solution over at http://blog.clintonbeattie.com/how-to-solve-the-jquery-flickering-content-problem/

In short, add overflow:hidden to the containing element that you are sliding in/out. Hope this helps!

Model Reject
+1  A: 

From what I've heard and tried (including the other suggestions here) there are still situations where the flicker will continue to be noticeable, especially when you don't have the choice of easily leaving quirks mode. In my case I had to stay on quirks mode for now and the other suggestions still didn't fix the problem for me. I ended up adding a little workaround until we can finally leave quirks mode:

//Start the slideUp effect lasting 500ms
$('#element').slideUp(500);

//Abort the effect just before it finishes and force hide()
//I had to play with the timeout interval until I found one that
// looked exactly right. 400ms worked for me.
setTimeout(function() {
    $('#element').stop(true, true).hide(); 
}, 400);
sergiopereira
A: 

I'm working with a carousel that has marked-up copy over some background slides. The slide transition is a fade. Everything's fine so far.

But some parts of the copy fade-in after the slide loads. And then fade-out right before the slide transition. This copy, an unordered list of links (UL > LI*2 > A), faded-in over the slide background. This, too, is fine in every browser except IE. IE had a flickering background on the UL.

What was happening is that there were two simultaneous fade-Ins running: the background image on the slide & the UL. I used sergio's prototyping setTimeout function to run the UL fadeIn() after the slide had completed loading. Then, I called another setTimeout to make the slide transition right after the UL fadeOut().

setTimeout is your friend when combating IE flicker.

Benxamin
A: 

This code does not depends on the browser (no browser detection), works great and reproduces the behaviour of the method .slideUp

$("#element").animate({
     height: 1,          // Avoiding sliding to 0px (flash on IE)
     paddingTop: "hide",
     paddingBottom: "hide"
     })
     // Then hide
     .animate({display:"hide"},{queue:true});
ghusse