hover时的不透明度(jQuery)
我们有一个链接:
Some text
当链接hover时,我们希望用一些动画改变不透明度。
我们怎么做?
像这样:
$('a:has(span)').hover( function() { $('span', this).fadeIn(); }, function() { $('span', this).fadeOut(); } );
另一种可能的方案
$("a span").hover(function(){ $(this).stop().animate({"opacity": 1}); },function(){ $(this).stop().animate({"opacity": 0}); });
如果你使用fadeOut(),跨度将崩溃,这样它就不会崩溃
编辑
这要好得多:
$('a:has(span)').hover(function() { $('span', this).stop().animate({"opacity": 1}); },function() { $('span', this).stop().animate({"opacity": 0}); });
使用.fadeTo() :
$( 'a' ).hover( function() { $( this ).fadeTo( 'fast', '1'); }, function() { $( this ).fadeTo( 'fast', '.4'); } );