Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Created September 22, 2010 12:03
Show Gist options
  • Save bil-bas/591559 to your computer and use it in GitHub Desktop.
Save bil-bas/591559 to your computer and use it in GitHub Desktop.
slideBulge function
// slideBulge function
// slides the top right menu bulge bg to the left/right to the requested position.
function slideBulge(currentPos, endPos) {
//stop the slideBulge function (if it is still looping)
clearTimeout(bulgeTimeout);
//set the jumpSize and jumpSpeed:
var jumpSize = 3;
var jumpSpeed = 10;
currentPos = parseInt(currentPos);
endPos = parseInt(endPos);
//if not already at endPos:
//(nb, remember we're going backwards (to the left) so slide if endPos is smaller)
var newPos = currentPos + (endPos > currentPos ? jumpSize : -jumpSize);
if ((newPos > currentPos && newPos >= endPos) ||
(newPos < currentPos && newPos <= endPos)) {
newPos = endPos;
} else {
bulgeTimeout = setTimeout("slideBulge('"+newPos+"', '"+endPos+"')", jumpSpeed);
}
//make the bg position adjustment:
document.getElementById('navs').style.backgroundPosition = newPos + 'px bottom';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment