Created
March 13, 2009 15:42
-
-
Save lincolnloop/78619 to your computer and use it in GitHub Desktop.
jQuery highlight and fade background on named anchors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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