I'm using a JQuery based css menu for my website. My problem however is if I click on one off the menu items. I want it to stay a cetain color, in my case the borrom half off the images.
I got my code from http://snook.ca/archives/javascript/jquery-bg-image-animations/ I used the second example. Heres the example page: http://snook.ca/technical/jquery-bg/
My code looks as follows
<script type="text/javascript">
$(function(){
$('#nav a')
.css( {backgroundPosition: "-20px 35px"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:800})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:800, complete:function(){
$(this).css({backgroundPosition: "-20px 35px"})
}})
})
});
</script>
If you hover over the menu the menu will change to a different color, that's the color I want the menu to stay when the menu is active and has been clicked on.
Hope someone could help me.
I tried as the answer said and still nothing
My modified code
<script type="text/javascript">
$(function(){
$('#nav a')
.css( {backgroundPosition: "-20px 35px"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:800})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:800, complete:function(){
$(this).css({backgroundPosition: "-20px 35px"})
}})
})
$('#nav a').click(function() {
$('#nav a:not(.selected');
$('#nav a').removeClass('selected');
$(this).addClass('selected');
})
});
</script>