Fix Jerky Scriptaculous (Script.aculo.us) Animation Effects

I was adding some BlindDown, BlindUp animation effects to something I was working on today with Scriptaculous and had a bit of an issue with jerky animation. I’ve had this before and ended up ditching them but never really investigated why sometimes they are smooth as nobody’s business and others not.

As it happened, today, I had it working nicely, made a change, and the issue arose, thus leading me to the cause.

It turns out that if you add a BlindDown or BlindUp animation to a div that has padding or a margin set in its CSS as the effect begins to execute the div jumps to the padding/margin size and then the BlindUp/BlindDown (or probably others but I haven’t investigated) works on the remaining ‘area’ of the element.

So this is jerky:

<script language="javascript" type="text/javascript">
    Effect.BlindDown("divJerky");
</script>
<div style="height:50px; padding:10px; display:none" id="divJerky">

</div>

The solution is this:

<script language="javascript" type="text/javascript">
    Effect.BlindDown("divJerky");
</script>
<div style="display:none" id="divJerky">
    <div style="height:50px; padding:10px">
    </div>
</div>

If you add the padding to an ‘inner’ div all is well in the world again and everything works smoothly…

I know this isn’t exactly astrophysics but it is Friday afternoon and I’ve only just realised what the issue was so I thought I’d share…

Have a good weekend :)

29 Responses to “Fix Jerky Scriptaculous (Script.aculo.us) Animation Effects”


  1. 1 Phil August 24, 2007 at 12:53 pm

    Oh my god! Thank you so much for “stumbling” over the cause and resulting fix to this problem… it has plagued me for months.

  2. 2 Graham Pengelly August 24, 2007 at 2:14 pm

    You’re welcome… I’m stuck on another one myself now where the animation jerks if there is a button within the div. I’ve not solved it yet but will be sure to update this when I do…

    Graham

  3. 3 Adam Robertson November 15, 2007 at 11:19 am

    I just tried what you instructed and it seems that the “height” property is actually makes the change! Note if you remove “height” from the style assignment, there’s still a little clunk at the end, but if you remove padding it’s still smooth. Could be my application… but either way is a solution!

    Any other reason you stopped using scriptaculous? I just started using it yesterday and I’d like to know if there’s something better so I don’t get really far into it before realizing it sucks :-P

    Thanks,

    Adam

  4. 4 Graham Pengelly November 15, 2007 at 12:31 pm

    Hi Adam…

    Thanks for dropping by. You might be right about the height, I’ll have to have a look.

    As for your second point I think Scriptaculous is a great library but not without its issues. I’ve been using jQuery for a while now and found it to be much better. It is tiny, really flexible and has a plug-in architecture that results in loads of additional functionality if you want it. I’d really suggest you have a look at that before you get too into Scriptaculous. (http://jquery.com/)

    Have fun

    Graham

  5. 5 John C. Worsley March 6, 2008 at 12:14 pm

    Thanks so much for this solution. You are a prince among men.

  6. 6 Jason Thompson July 2, 2008 at 12:32 am

    Just what I was looking for. Thanks.

  7. 7 Nico July 8, 2008 at 8:32 pm

    I have a jerky effect when the blind down tag is an ordered list
    or when the is inside the blind down tag. In firefox the list initially appears lower that it actually is; when the blinddown has finished it jumps upwards to the correct position (about 20px). the list b Haven’t found a way to fix this yet. Any ideas?

    Nico

  8. 8 Graham Pengelly July 8, 2008 at 8:42 pm

    Hi Nico

    Have you tried wrapping it in a div and using that for the blinddown?

    Graham

  9. 9 Nico July 9, 2008 at 6:15 am

    “Have you tried wrapping it in a div and using that for the blinddown?”

    Yes. Also I tried removing all styles. No success.

  10. 10 pdaddy October 27, 2008 at 12:13 am

    Pure gold!

    I’ve got all over the shop now, but she’s smooth. For me, there was a with width, which I had to move into an inner div.

    Also, The jerks didn’t seem to be present in MSIE6, just Safari and FFx (3 in both cases)

    JQuery does seem to have the momentum at the moment, pity it’s not just included in your rails apps for free.

  11. 11 pdaddy October 27, 2008 at 12:17 am

    Foolish of me to think that HTML tags would not get eaten in a blog comment, what I meant to say was:

    “I’ve got divs all over the shop now, but she’s smooth. For me, there was a td with width, which I had to move into an inner div.”

    the rest held up OK

  12. 12 Doug November 25, 2008 at 12:38 am

    Also found that if, in your container, there’s an element that has a margin or padding top, it’ll mess up.

    Example:
    div
    h4 Title /h4
    /div

    Will cause the jump unless the h4 has padding-top:0 and margin-top:0;

  13. 13 M December 1, 2008 at 11:55 am

    Thanks, helped me to fix the problem.

  14. 14 yassine December 15, 2008 at 3:44 pm

    أتمنى ان تفيدونا بالجديد

  15. 29 Joe August 24, 2009 at 4:56 pm

    Cool man you helped me fix my issue :) Thanks!


Leave a Reply




a