my jQuery skills are pretty good normally but this is driving me mad!
It's a fairly simple accordian I've coded up from scratch. Using jQuery 1.3.2 so there shouldn't be any jumping bugs but basically if you take a look at the example:
http://www.mizudesign.com/jquery/accordian/basic.html
I'm displaying the height for the target div on the right - if it contains text it thinks it's shorter than it is and jumping. If it's an image there's no problem.
I can't figure out where I'm going wrong - it's obviously in the CSS somewhere but I've tried all the usual suspects like display:block
Any ideas would be gratefully received!
Yours, Chris
PS Please forgive the nature of the source code, I've ripped it out the whole project I'm working on so it does include some divs that don't really need to be there.
I think the problem is, that when padding or margin is added then it jumps, this was the case by me. you have to animate the margin in the callback
Also "keep in mind" that tables behave buggy with slideDown slideUp and rather use fadeIn fadeOut
I also had an annoying
slideUp()
jump issue that occurred on Safari, but not chrome or IE. It turned out that the div tag I was hiding/showing was right below another div tag that containedfloat:left
divs. During sliding up, the floating divs would be momentarily re-rendered causing the jump.The fix was simply adding
clear:both
to the style of the hiding/showing div.My problem is that since I have a responsive design I don't know what the width or height of my element is going to be. After reading this blog post http://www.bennadel.com/blog/2263-Use-jQuery-s-SlideDown-With-Fixed-Width-Elements-To-Prevent-Jumping.htm I realized that jQuery was changing the position of my element to fixed and messing with the layout of the element. I added the following to my CSS for the element and didn't notice any bad side effects in IE7+, firefox, chrome and safari.
The issue is due to IE (quirks mode) trying to render "height:0px".
The fix: Animate height to 1 (not 0), then hide and reset height:
I must admit I've found my own dynamic solution now.
http://www.mizudesign.com/jquery/accordian/basic.html should be fixed.
It's very simple really - just adds the height using .css before hiding the div. Works a treat :)
Replacing margin-top and margin-bottom values with padding-top and padding-bottom values did the trick for me. Don't forget to set the margin value to 0 after this.