jQuery在悬停时动画文本颜色

前端之家收集整理的这篇文章主要介绍了jQuery在悬停时动画文本颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用以下代码,尝试在悬停时获取字体颜色动画,类似于我的边框底色动画.更改边框底部颜色效果很好,但字体颜色似乎不会改变.这里可以看到一个完整的例子: http://www.buenolisto.com/alma.非常感谢任何帮助.我也在调用jQuery UI: https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js
  1. jQuery("li.social").hover(function() {
  2. jQuery(this).find("img").stop(true,true).animate({
  3. 'marginTop': "-=20px"
  4. },'fast');
  5. },function() {
  6. jQuery(this).find("img").stop(true,true).animate({
  7. 'marginTop': "+=20px"
  8. },'fast');
  9. })
  10. jQuery("li.reservas").hover(function() {
  11. jQuery(this).find("img").stop(true,true).fadeOut({
  12. 'marginTop': "-=30px"
  13. },'slow');
  14. },true).fadeIn({
  15. 'marginTop': "+=30px"
  16. },'slow');
  17. })
  18. jQuery("ul.menu li").hover(function() {
  19. jQuery(this).find("a").stop(true,true).animate({
  20. 'borderBottomColor': '#2E9ECE','color': '2E9ECE'
  21. },function() {
  22. jQuery(this).find("a").stop(true,true).animate({
  23. 'borderBottomColor': '#FFDF85','color': 'FFDF85'
  24. },'slow');
  25. })​

解决方法

通过查看你的代码,我可以告诉你,你已经忘记了#css颜色附近,所以代替这个’颜色’:’2E9ECE’使用这个’颜色’:’#2E9ECE’.你可能也想要你的风格,我已经重写你最后一次悬停到这样的事情:
  1. $('ul.menu li a').hover(
  2. function() {
  3. // do this on hover
  4. $(this).animate({
  5. 'borderBottomColor': '#2E9ECE','color': '#2E9ECE'
  6. },'slow');
  7. },function() {
  8. // do this on hover out
  9. $(this).animate({
  10. 'borderBottomColor': '#FFDF85','color': '#FEFEFE'
  11. },'slow');
  12. }
  13. );

在我看来,这更具可读性和更短.看一下jQuery API hoveranimate

更新:我已经验证,此代码有效(使用最新版本的FireFox和Chrome测试):

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  4. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
  5. <script type="text/javascript">
  6. $(function() {
  7. $("a").hover(
  8. function() {
  9. $(this).animate({ color: "#00ff00" },'slow');
  10. },function() {
  11. $(this).animate({ color: "#ff0000" },'slow');
  12. });
  13. });
  14. </script>
  15. </head>
  16. <body>
  17. <a href="#">aaa</a><br />
  18. <a href="#">bbb</a><br />
  19. </body>
  20. </html>

猜你在找的jQuery相关文章