我有一种感觉,这是由我的函数设置方式引起的,但是每次将鼠标移到元素上时,都会多次调用悬停事件(我只希望在鼠标悬停在元素,以及当鼠标离开元素时(因此不再在它上面)。
这是代码:
$(document).ready(function(){
$('#about-us-facebook-default').hover(
function(){
$(this).css({'display':'none'});
$('#about-us-facebook-hover').css({'display':'block'});
},
function(){
$(this).stop(true,true).css({'display':'block'});
$('#about-us-facebook-hover').css({'display':'none'});
}
);
});
布局:
<div class="about-contact-button">
<a href="http://www.facebook.com/BlackTiePhotographers" id="about-us-facebook-hover" >
<img src="http://blacktiephotographers.com/wp-content/uploads/2012/03/facebook-hover.png" alt="" title="Connect with us on Facebook" width="30" height="30" class="alignnone size-full wp-image-2267" /></a>
<a href="http://www.facebook.com/BlackTiePhotographers" id="about-us-facebook-default">
<img src="http://blacktiephotographers.com/wp-content/uploads/2012/03/facebook.png" alt="Join Black Tie Photographers on Facebook" title="Connect with us on Facebook" width="30" height="30" class="alignnone size-full wp-image-2266" /></a>
<a href="http://www.facebook.com/BlackTiePhotographers">Join on Facebook</a>
</div>