views:

115

answers:

1

I would like to be able to use jQuery's scrollTo plugin to animate the window scroll down to a div when Google directions are loaded. Could someone please help me convert the setTimeout line to jQuery and use scrollTo to animate the scroll? Here is the javascript that doesn't scroll:

      GEvent.addListener(gdir, 'load',  onGDirectionsLoad)

     function onGDirectionsLoad(){ 
      setTimeout('eval(\'window.location = "#directions"\;\')', 500); 

     }
+2  A: 

Use an anonymous function rather than eval():

function onGDirectionsLoad() {
  setTimeout(function(){
    $.scrollTo("#directions", 1000);
  }, 500);
}

* Uses Ariel Flesler's $.scrollTo() jQuery Plugin.

Jonathan Sampson