hacking jquery's easyslider for faster jumps

easyslider is a terrific jquery plugin for condensing lots of information into a few "slides" that the user can jump to.  demo is here.

the problem is when you have a long list of items to display.  if i have 10 items, and i want to jump from item 1 to item 10, there is a very long delay.  currently, easyslider uses the current formula to calculate how long it takes to do a jump:

var speed = diff*options.speed;

so if there's a difference of 9, it says 9*1000, or 9 seconds for the jump to complete, assuming 1000 milliseconds is your default pause time.

there's a better way to handle this, IMHO.  for example, using the formula below:

var speed = Math.abs(options.speed/(diff/2));

let's use a few examples to show how this is a bit faster.

  • if you jump from item 1 to item 10, your difference is 9.  if you divide by half of that, your jump time is 1000/4.5, or 200 milliseconds.
  • if you jump from item 1 to item 5, your difference is 4.  1000/2 will result in a delay of 500 milliseconds.
i added a check to see if the user clicked on the same item, which can screw up the math a bit:

if (speed > options.speed) { speed = options.speed; } // reset the speed back to normal

you can insert these two lines into the animate function and your jumps will be faster.  the complete function is here on pastie.  as a disclaimer, i threw this together pretty quickly and it's just a quick hack at this point.  i'm sure it could be improved upon and implemented into easyslider.  clearly this particular snippet won't work for abnormally large numbers, like 100.

edit: if the above snippet is too fast, consider trying out this variation:

var speed = Math.abs(options.speed/(diff/(s/2))); // s is the number of items in your list