I am trying to do a simple jQuery slideToggle()
on a DIV containing text and have found the animation to be very sluggish (seems to hesitate) as the slideDown
animation nears the bottom of the sliding DIV.
Code and example of this may be found here. I have tested on several computers and all modern versions of the popular browsers, all behave the same way. Strangely, when I run the exact same page in jsFiddle, it is smooth.
Any ideas?
UPDATE
Part of this seems to be, like someone else suggested, that jQuery does not know the height of the sliding DIV before the animation runs. Since the content in the sliding DIV will be dynamic and either very short or somewhat long, neither do I. So, I tried grabbing the height of the DIV prior to hiding it with jQuery and then setting the CSS height accordingly. Made for a somewhat smoother animation but probably not the best solution - demo
UPDATE 2
It would appear that the problem was due to several CSS issues with the initial example. First, way too many DIVs. Second, the sliding DIV had padding set - does not play well
with toggleSlide
, and finally, the sliding DIV was in a container DIV that also contained the #control-container
(button) DIV.
Reducing the DIVs down to two (outer DIV for the sliding element and the sliding DIV itself) and not setting the outer sliding DIV padding seemed to do the trick - final example.