I've been struggling with the code below as it doesn't seem to be working. I had a simpler code before for swapping images, so if there's an easier way to achieve this, I'm open to suggestions.
Just to recap, I'm trying to:
1. Land on home page > No selection in nav 2. Hover over - image switches to selected state 3. Click on image swaps to selected state
Thanks for any assistance!
Another issue I'm facing is that the images provided by the artist include text within the image itself. So, I have two different versions of each image - one in active state with text and another in inactive state with text. This makes it difficult to place text above the image.
Jquery
var menu = {
init: function () {
$('.nav-image').hover(function () {
if (!$(this).attr('id') != menu._selectedId + '-nav' && $(this).attr('src').indexOf("_on.png") == -1) {
var src = $(this).attr('src').replace("_off.png", "_on.png");
$(this).attr('src', src);
}
},
function () {
if ((page == "index" && $(this).attr('id') != "index-nav") || (page == "about" && $(this).attr('id') != "about-nav") || (page == "portfolio" && $(this).attr('id') != "portfolio-nav") || (page == "blog" && $(this).attr('id') != "blog-nav") || (page == "contact" && $(this).attr('id') != "contact-nav") || page == "index") {
if (!$(this).attr('id') != menu._selectedId + '-nav' && $(this).attr('src').indexOf("_on.png") >= 0) {
var src = $(this).attr('src').replace("_on.png", "_off.png");
$(this).attr('src', src);
}
}
});
}}
HTML
<div class="menu">
<div style="float: left; hieght: 45px; width: 193px;"><img src="images/nav/left_end.png" class="nav-image"></div>
<div style="float: left; height: 45px; width: 73px;"><a href="index.php"><img src="images/nav/home_off.png" class="nav-image" id="index-nav"></a></div>
<div style="float: left; height: 45px; width: 80px;"><a href="about.php"><img src="images/nav/about_off.png" class="nav-image" id="about-nav"></a></div>
<div style="float: left; height: 45px; width: 112px;"><a href="portfolio.php"><img src="images/nav/portfolio_off.png" class="nav-image" id="portfolio-nav"></a></div>
<div style="float: left; height: 45px; width: 69px;"><a href="http://info.arkmediainc.com/blog"><img src="images/nav/blog_off.png" class="nav-image" id="blog-nav"></a></div>
<div style="float: left; height: 45px; width: 98px;"><a href="http://info.arkmediainc.com/contact-us"><img src="images/nav/contact_off.png" class="nav-image" id="contact-nav"></a></div>
<div style="float: left; height: 45px; width: 35px;"><img src="images/nav/right_end.png"></div>
</div>