Skip to content
Advertisement

slideDown jumps abruptly at the end

I’ve built a fairly normal menu-submenu arrangement in a vertical column — nested ULs, using slideToggle to expand and collapse submenus.

The problem I’m trying to solve is in the way the submenus “jump” open at the very end. (I’m testing in the latest release of Chrome.) It’s probably most noticeable in the second submenu, “Benefits”. It doesn’t jump when menus are collapsing, only when they’re expanding.

I thought that the problem might have something to do with the :after styles being added only when the menu is fully expanded. Specifically, the class current is added to the LI tag once the menu is fully expanded. But commenting out the code that toggles that class seems to have no effect.

JavaScript
JavaScript
JavaScript

View on jsFiddle

Advertisement

Answer

Give the element you are slidetoggling a set width.

http://jsfiddle.net/5gGum/6/

JavaScript

This allows jQuery to accurately calculate the end height.

For reference, I learned about this little trick from here: http://www.bennadel.com/blog/2263-Use-jQuery-s-SlideDown-With-Fixed-Width-Elements-To-Prevent-Jumping.htm

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement