jquery mouseover,mouseout and click
I have a sprite menu and I am using jquery for the mouseover, mouseout and click. The mouseover and mouseout work fine but I want is if I click and selected a menu then change the background position. It is now my problem, it doesn't work, maybe because once I click a menu then the mouseout still triggered.
here is my jquery
$(document).ready(function(){
$(function(){
$('#a a')
.css( {backgroundPosition: "0 -33px"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
})
.mouseout(function(){
开发者_JS百科 $(this).stop().animate({backgroundPosition:"(0 -33px)"}, {duration:200, complete:function(){
$(this).css({backgroundPosition: "0 -33px"})
}})
})
});
});
my css
h2 {clear:both;padding-top:20px;}
ul {list-style:none;margin:0;padding:0;}
li {float:left;width:120px;margin:0;padding:0;text-align:center;}
li a {display:block;padding:5px 10px;height:100%;color:#FFF;text-decoration:none;}
li a:hover, li a:focus {background-position:0 0;}
li a:active {background-position:-66px 0;}
#a a {background:url(<?php echo base_url() ?>images/tabs.png) repeat 0 -33px;}
my html
<h2>Top down</h2>
<ul id="a">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
Animating background-position is not possible with the current jQuery core unless you use the jQuery background position effect plugin - http://plugins.jquery.com/project/backgroundPosition-Effect
精彩评论