2010-07-02 50 views

回答

5

另一种可能是CSS过渡期间财产。这不会让它在指定的时间内保持纯色,但它可以允许从一种颜色转换到另一种颜色,例如需要几秒钟。这可能不被某些浏览器访问页面所支持,所以使用jQuery的其他答案对此很有帮助。

a { 
    color: red; 
    transition-duration: 5s; 
    -moz-transition-duration: 5s; 
    -webkit-transition-duration: 5s; 
} 

a:hover { 
    color: blue; 
} 
+0

雅没有那么重要,这在FF和Chrome中非常有用,谢谢! – thegreyspot 2010-07-02 14:27:31

4

当然!如果你想有链接淡出,你需要jQuery UI的动画色彩:

$('#myLinkId').hover(
    function(e){ 
    //mouseover 
    $(this).css('color','blue'); 
    }, 
    function(e){ 
    //mouseout 
    $(this).animate({color:'black'},300); //300 is the speed of the animation in ms 
    } 
); 

动画文档:http://api.jquery.com/animate/

+2

您需要使用jQuery UI来设置颜色的动画效果。 – sje397 2010-07-02 04:02:08

+0

好点,谢谢!我会在我的答案中记下一个字。 – 2010-07-02 04:07:12

+1

使用另一个插件进行简单的任务?我真的认为你需要这个jQuery UI ... – Reigel 2010-07-02 04:09:06

4

demo

CSS

a { 
    color: red; 
} 

a.blue { 
    color: blue; 
} 

HTML

<a href="index.html">home</a> 

jQuery的

$(document).ready(function(){ 
    $('a').hover(function(){ 
     $(this).addClass('blue'); 
    }, 
    function(){ 
     var link = $(this); 
     setTimeout(function(){link.removeClass('blue');},1000); 
    }) 
}) 

demo

+0

Very不错,我要用这个! – Pierreten 2010-07-02 04:25:15

+0

任何方式使它淡出,而不是只是在1000毫秒后切换回来(对不起,我没有提及有问题) – thegreyspot 2010-07-02 04:28:17

+0

@thegreyspot - 如果是这样的话,使用Jon Weers的答案.. – Reigel 2010-07-02 04:42:58