So I have a hover function that is supposed to move an arrow under the corrent the link that someone hovers over. The problem is, the arrow never returns to the current link when the person stops hovering over the link. However, if I set the left properly with a constant value it works. Anyone have any ideas?
Here is the js:
$('#navbar li').hover(function(event) {
var currentId = '#' + $('body').attr('id') + '_link';
var xCordCurrent = $(currentId).offset().left - ($('#arrow').width() / 2);
var xCordHover = $(event.target).offset().left + ($(event.target).width() / 2) - ($('#arrow').width() / 2);
$('#arrow').animate(
{ left: xCordHover }, {
duration: 'slow',
easing: 'easeOutBack'
})
}, function(event) {
$('#arrow').animate(
{ left: xCordCurrent }, {
duration: 'slow',
easing: 'easeOutBack'
})
});
And here is the html:
<div id="arrow"></div>
<ul id="navbar">
<li id="home_link"><a href="/">home</a></li>
<li id="portfolio_link"><a href="portfolio.php">portfolio</a></li>
<li id="resume_link"><a href="resume.php">resume</a></li>
<li id="photos_link"><a href="photography.php">photos</a></li>
<li id="blog_link"><a href="blog/">blog</a></li>
</ul>