我们有一个链接:
<a href="#">
Some text
<span style="width: 50px; height: 50px; background: url(image.png); overflow: hidden; opacity: 0;"></span>
</a>
<span>
当链接悬停时,我们想用一些动画改变不透明度。
我们会怎么做?
另一种可能的解决方案:
$("a span").hover(function(){
$(this).stop().animate({"opacity": 1});
},function(){
$(this).stop().animate({"opacity": 0});
});
如果你使用fadeOut(),span会崩溃,这样就不会
编辑
这要好得多:
$('a:has(span)').hover(function() {
$('span', this).stop().animate({"opacity": 1});
},function() {
$('span', this).stop().animate({"opacity": 0});
});
像这样:
$('a:has(span)').hover(
function() { $('span', this).fadeIn(); },
function() { $('span', this).fadeOut(); }
);