How to animate scrollTop to an offset, when it is animating a font resize concurrently, changing the offset value

How to animate scrollTop to an offset, when it is animating a font resize concurrently, changing the offset value

I've managed to create a zoom and scroll effect but it breaks if I have them run concurrently.  When clicking on an element it is meant to zoom in scale with that element's depth (this works), and then scroll the page so that the top of the element is at the top of the viewport.  This only works if I click on elements of equal depth to the current one, as the value of the offset is no longer valid after all the elements have been zoomed.

Interrupting the process with an alert allows correct behaviour to occur, as it allows the value to 'catch up'.

Here's the code I'm using:

  1. (t = $("#contents .chapter")).click(zoomadjust = function(evt) {
  2.     if(this != zoomednode) {
  3.       var zoom,  depth, t;
  4.       if(!zoomednode)
  5.         zoomednode = $(this).parents("ul")[0];
  6.       t = depth = $(this).parents("ul").length;
  7.       zoom = 130;
  8.       while(--t > 0)
  9.         zoomnum = (zoom *= 1.15);
  10.       zoom += '%';
  11.       depth -= $(zoomednode).parents("ul").length;
  12.       if(depth < 0)
  13.     depth *= -1;
  14.       zoomednode = this;
  15.       $("#contents").animate(
  16.         { fontSize: zoom,
  17.     },
  18.         {duration: 45+45*depth, queue: false }, 0, 0
  19.       );
  20.       $("html, body").animate(
  21.     { scrollTop: $(zoomednode).offset().top, {duration: 45+45*depth, queue: false });
  22.     }
  23.   })
I've tried predicting the value by scaling it up, but it doesn't seem to help.

EDIT: Wonder if lambda expressions can do what I'm seeking, let's have a look...

UPDATE: Nope, didn't work.  I tried
  1. $("html, body").animate(
  2.     { scrollTop: function() { return $(zoomednode).offset().top } }, {duration: 45+45*depth, queue: false });

in the hope that it would always use the most up-to-date value each time it is referenced, but it seems that isn't supported...