Jeff Karbowski
Jeff Karbowski

Reputation: 11

Scroll window after timeout

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); 

        }

Upvotes: 1

Views: 2218

Answers (1)

Sampson
Sampson

Reputation: 268334

Use an anonymous function rather than eval():

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

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

Upvotes: 2

Related Questions