Skip to content

Instantly share code, notes, and snippets.

@lincolnloop
Created March 13, 2009 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lincolnloop/78619 to your computer and use it in GitHub Desktop.
Save lincolnloop/78619 to your computer and use it in GitHub Desktop.
jQuery highlight and fade background on named anchors
// highlight and fade background on named anchors
// requires jquery.color.js http://plugins.jquery.com/project/color
function highlight(elemId){
var elem = $(elemId);
elem.css("backgroundColor", "#ffffff"); // hack for Safari
elem.animate({ backgroundColor: '#ffffaa' }, 1500);
setTimeout(function(){$(elemId).animate({ backgroundColor: "#ffffff" }, 3000)},1000);
}
if (document.location.hash) {
highlight(document.location.hash);
}
$('#main a[href*=#]').click(function(){
var elemId = '#' + $(this).attr('href').split('#')[1];
highlight(elemId);
});
// highlight background on named anchors
// requires jquery.color.js http://plugins.jquery.com/project/color
// ** can't animate to transparent, use css instead **
function highlight(elemId){
$(elemId).animate({ backgroundColor: '#ffffaa' }, 1500);
setTimeout(function(){$(elemId).css({ 'backgroundColor': 'transparent' })},1000);
}
if (document.location.hash) {
highlight(document.location.hash);
}
$('#main a[href*=#]').click(function(){
var elemId = '#' + $(this).attr('href').split('#')[1];
highlight(elemId);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment