I have the following code to animate the showing/hiding of a div.
$(".headerClosed, .headerOpen").live("click", function(){
$(this).next().slideToggle("slow");
}
This shows and hides a div with the following markup:
<div class="details">
<p>Date</p>
<p>Text</p>
</div>
The problem is in IE(surprise, surprise!) when the div slides down the animation is smooth until the end when it jerks. I know this is due to the padding/margin settings of the div.
If I use a <div> instead of <p> then the animation is smooth, but as soon as I add any padding or margin to the <div> then the animation jerks. How can you slide down a nice looking div with spacing if the padding and margin settings make it jerk?
jQuery Animations - The animate() Method. The jQuery animate() method is used to create custom animations. Syntax: $(selector).animate({params},speed,callback); The required params parameter defines the CSS properties to be animated. The optional speed parameter specifies the duration of the effect.
The following example demonstrates the slideToggle () method: Use a jQuery method to slide up a <div> element. $ ("div"). (); For a complete overview of all jQuery effects, please go to our jQuery Effect Reference.
With jQuery you can create a sliding effect on elements. The jQuery slideDown () method is used to slide down an element. The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.
The “silder” is a thin and basic jQuery plugin that allows you to create animated image slider. You just need to place your images in slider’s HTML structure. After that, this plugin render a beautiful fullscreen animated image slider with next previous buttons.
Your margins are likely collapsing. When you apply a float
, overflow: auto
or overflow: hidden
to the slided element, that should no longer occur.
jQuery sets overflow: hidden
during the animation, so the margins don't collapse. When the animation is done, this property is removed. The margins of the <p>
collapse again, hence you get a little jerky jump at the end.
Wrap the div inside another div. Add the padding/margin to the inner div, and call the animation on the outer div.
<div class="details">
<div class="hasMargins">
<p>Date</p>
<p>Text</p>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With