Skip to content

Instantly share code, notes, and snippets.

@jasonwyatt
Created November 18, 2010 17:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwyatt/705294 to your computer and use it in GitHub Desktop.
Save jasonwyatt/705294 to your computer and use it in GitHub Desktop.
Fade out a google maps polyline.
function fadeOut(line, keepAround, fadeDuration){
keepAround = keepAround || 1000;
fadeDuration = fadeDuration || 500;
setTimeout(function(){
var startingOpacity = line.strokeOpacity,
startTime = (new Date()).getTime();
function step(){
var currentTime = (new Date()).getTime(),
elapsed = currentTime - startTime,
targetOpacity = startingOpacity - startingOpacity * (elapsed/fadeDuration);
line.setOptions({
strokeOpacity: targetOpacity
});
if(elapsed >= fadeDuration){
line.setMap(null);
} else {
setTimeout(step, 30);
}
}
setTimeout(step, 30);
}, keepAround);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment