I had this expand/collapse div on which I was using slideToggle to make it look good. However, in quirks mode (HTML Transitional 4.01 DocType) and on IE7 the div would briefly pop up after collapsing, showing an annoying flicker. It seems that Internet Explorer has a problem rendering stuff with height 0px.

The solution I found: replace target.slideUp(speed,callBack) with
var h = target.height();
var cssHeight=target.css('height');
target.animate(
{ height: '1px' }, speed, function() {
target.hide();
target.height(h);
target.css('height',cssHeight);
callBack();
}
);
I have also created a jQuery ticket to suggest they use the same method in the library itself.

Update 1 Sep 2009: I have added the cssHeight variable to restore the actual css height settings, not just the height.

Update 21 May 2011: commenter Mads shared a more elegant solution in the form of this script:
(function(){
// Define overriding method.
jQuery.fx.prototype.hide = function(){

// Remember where we started, so that we can go back to it later
this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
this.options.hide = true;

// Begin the animation
this.custom(this.cur(), 1);
}
})();
used anywhere after the jQuery include. Thanks, man!

Comments

Mads

<p>If you don't want to use a custom version of jQuery, you could always override the core method like this:<br><br>(function(){<br> // Define overriding method.<br> jQuery.fx.prototype.hide = function(){<br><br> // Remember where we started, so that we can go back to it later<br> this.options.orig[this.prop] = <a href="http://jQuery.style" rel="nofollow noopener" title="jQuery.style">jQuery.style</a>( this.elem, this.prop );<br> this.options.hide = true;<br><br> // Begin the animation<br> this.custom(this.cur(), 1);<br> }<br>})();<br><br>Just paste the above script, anywhere after your jQuery include, and you'll be fine.<br><br>This is not a perfect solution, as you have to make sure the hide method dosn't change, upon update of jQuery source. However the method hasn't changed in 2 years or more, so chances are that it won't anytime soon.</p>

Mads

Anonymous

<p>The issue still exists in jQuery v 1.5.3 and v1.6.1.</p>

Anonymous

Mads

If you don&#39;t want to use a custom version of jQuery, you could always override the core method like this:<br><br>(function(){<br> // Define overriding method.<br> jQuery.fx.prototype.hide = function(){<br><br> // Remember where we started, so that we can go back to it later<br> this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );<br> this.options.hide = true;<br><br> // Begin the animation<br> this.custom(this.cur(), 1);<br> }<br>})();<br><br>Just paste the above script, anywhere after your jQuery include, and you&#39;ll be fine.<br><br>This is not a perfect solution, as you have to make sure the hide method dosn&#39;t change, upon update of jQuery source. However the method hasn&#39;t changed in 2 years or more, so chances are that it won&#39;t anytime soon.

Mads

Anonymous

The issue still exists in jQuery v 1.5.3 and v1.6.1.

Anonymous

Tony Lea

<p>Thanks, This issue should be resolved with the latest version of jQuery. Please feel free to check out the following resource for a beginner rundown of the jquery slideup and slidedown functionality: <a href="http://www.tonylea.com/2010/jquery-slideup-and-slidedown/" rel="nofollow noopener" title="http://www.tonylea.com/2010/jquery-slideup-and-slidedown/">http://www.tonylea.com/2010...</a></p>

Tony Lea

Tony Lea

Thanks, This issue should be resolved with the latest version of jQuery. Please feel free to check out the following resource for a beginner rundown of the jquery slideup and slidedown functionality: http://www.tonylea.com/2010/jquery-slideup-and-slidedown/

Tony Lea

Anonymous

<p>Thanks buddy for saving my 2 days effort<br>my effort was about to scrapped just because of this annoying flickering<br><br>I used your slideUp and made similar slideDown here is slideDown function :D<br><br>var h = target.height();<br> var cssHeight = target.css('height');<br> target.height('1px');<br> target.css('height', '1px');<br> <a href="http://target.show" rel="nofollow noopener" title="target.show">target.show</a>();<br> target.animate({ height: h }, 500, function() {<br> target.height(h);<br> target.css('height', cssHeight);<br> }<br> );</p>

Anonymous

Anonymous

Thanks buddy for saving my 2 days effort<br>my effort was about to scrapped just because of this annoying flickering<br><br>I used your slideUp and made similar slideDown here is slideDown function :D<br><br>var h = target.height();<br> var cssHeight = target.css(&#39;height&#39;);<br> target.height(&#39;1px&#39;);<br> target.css(&#39;height&#39;, &#39;1px&#39;);<br> target.show();<br> target.animate({ height: h }, 500, function() {<br> target.height(h);<br> target.css(&#39;height&#39;, cssHeight);<br> }<br> );

Anonymous

Anonymous

<p>Thanks buddy. It really saved my day.</p>

Anonymous

Moose

<p>Yeah, I tried changing the doctype, too. It fixed the issue but it also hosed the rest of the site's layout. <br><br>Our site is an ancient piece of crap, probably with the wrong doctype anyway, but until we re-build it, this was a great fix.</p>

Moose

Siderite

<p>Well, wouldn't it be nice if changing the doctype for all the pages in a large project would fix anything, rather than a single line of code in jQuery?<br><br>For me, that was not an option (although I have tried to convince the stakeholders) so I am working with my own patched jQuery.</p>

Siderite

Moose

Yeah, I tried changing the doctype, too. It fixed the issue but it also hosed the rest of the site&#39;s layout. <br><br>Our site is an ancient piece of crap, probably with the wrong doctype anyway, but until we re-build it, this was a great fix.

Moose

Ofer

<p>John Resig just changed that ticket status to "wontfix" due to the fact that setting the page to Strict Mode fixes the issue.</p>

Ofer

Siderite

Well, wouldn&#39;t it be nice if changing the doctype for all the pages in a large project would fix anything, rather than a single line of code in jQuery?<br><br>For me, that was not an option (although I have tried to convince the stakeholders) so I am working with my own patched jQuery.

Siderite

Ofer

John Resig just changed that ticket status to &quot;wontfix&quot; due to the fact that setting the page to Strict Mode fixes the issue.

Ofer

Moose

<p>Changing 0 to 1 in this.custom(this.cur(), 1); worked for me!<br><br>Thanks SO much. This was bugging the crap out of me!!!</p>

Moose

Moose

Changing 0 to 1 in this.custom(this.cur(), 1); worked for me!<br><br>Thanks SO much. This was bugging the crap out of me!!!

Moose

Anonymous

<p>Many thanks for your solution, it took me on the right path. But sadly your code isn't working well on my side. If i want to reshow the hidden element (slideDown()) it behaves even worse compared to the flickering on hiding / slideUp.<br><br>So - what did the trick:<br>I just changed in the original jQuery script the function for minimizing the element to the height 1 instead of 0.<br><br>Here is the code:<br><br><br>// Simple 'hide' function<br> hide: function(){<br> // Remember where we started, so that we can go back to it later<br> this.options.orig[this.prop] = jQuery.attr( <a href="http://this.elem.style" rel="nofollow noopener" title="this.elem.style">this.elem.style</a>, this.prop );<br> this.options.hide = true;<br><br> // Begin the animation<br> this.custom(this.cur(), <b>1</b>);<br> },<br><br><br>I just change 0 to 1...<br><br>Let me know if it works for you.</p>

Anonymous

Anonymous

Many thanks for your solution, it took me on the right path. But sadly your code isn&#39;t working well on my side. If i want to reshow the hidden element (slideDown()) it behaves even worse compared to the flickering on hiding / slideUp.<br><br>So - what did the trick:<br>I just changed in the original jQuery script the function for minimizing the element to the height 1 instead of 0.<br><br>Here is the code:<br><br><br>// Simple &#39;hide&#39; function<br> hide: function(){<br> // Remember where we started, so that we can go back to it later<br> this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );<br> this.options.hide = true;<br><br> // Begin the animation<br> this.custom(this.cur(), <b>1</b>);<br> },<br><br><br>I just change 0 to 1...<br><br>Let me know if it works for you.

Anonymous

Siderite

<p><b>slideUp</b> is the method you use in your code and that results in problems on <i>Internet Explorer</i>. What I am suggesting is using the piece of code in the post instead of <b>slideUp</b> when <i>IE</i> is used.<br><br>I have looked into the <i>jQuery</i> animation engine to see if I can fix <b>slideUp</b> directly, but it was too complicated for my alloted time.</p>

Siderite

Siderite

<b>slideUp</b> is the method you use in your code and that results in problems on <i>Internet Explorer</i>. What I am suggesting is using the piece of code in the post instead of <b>slideUp</b> when <i>IE</i> is used.<br><br>I have looked into the <i>jQuery</i> animation engine to see if I can fix <b>slideUp</b> directly, but it was too complicated for my alloted time.

Siderite

Moose

<p>Hi,<br><br>I am running jQuery JavaScript Library v1.3.2 but cannot find the line you reference to fix the IE flicker bug:<br><br>target.slideUp(speed,callBack)<br><br>Am I looking at the correct file? I'd love to fix this bug.<br><br>Thanks so much.</p>

Moose

Moose

Hi,<br><br>I am running jQuery JavaScript Library v1.3.2 but cannot find the line you reference to fix the IE flicker bug:<br><br>target.slideUp(speed,callBack)<br><br>Am I looking at the correct file? I&#39;d love to fix this bug.<br><br>Thanks so much.

Moose

Anonymous

<p>Thank you!<br>The IE bug is still not resolved in jQuery 1.3.2. All the "IE peek-a-boo" hacks didn't work for me. This has, and it is by far a much more elegant solution.</p>

Anonymous

Anonymous

Thank you!<br>The IE bug is still not resolved in jQuery 1.3.2. All the &quot;IE peek-a-boo&quot; hacks didn&#39;t work for me. This has, and it is by far a much more elegant solution.

Anonymous

Post a comment