Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery IE jerky slide animation

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?

like image 640
Fermin Avatar asked May 26 '09 10:05

Fermin


People also ask

How do you animate in jQuery?

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.

How to slide up a <div> element using jQuery?

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.

How to create a sliding effect on elements using jQuery?

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.

How to create animated image slider with jQuery?

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.


2 Answers

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.

like image 148
vdboor Avatar answered Oct 28 '22 12:10

vdboor


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>
like image 24
Sam Wessel Avatar answered Oct 28 '22 13:10

Sam Wessel