Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover animation with jquery

Tags:

jquery

I have written a very basic jquery script that is true theorically but not in browser:

<ul class="menUl">
  <li> <a href="#">TEMPLATE<span>DESIGN</span></a> </li>
  <li> <a href="#">FRONTEND<span>CODING</span></a> </li>
  <li> <a href="#">SERVESIDE<span>CODING</span></a> </li>
  <li> <a href="#">CONTACT<span>ME</span></a> </li>
</ul>

jQuery:

$(document).ready(function(){
  $(".menUl li a").hover(function() {
    $(this).animate({color: "#c7ce95" }, 600);
  },function() {
    $(this).animate({ color: "#807e7c" }, 400);
  });
});

What is wrong with my code? http://jsfiddle.net/GGnb7/ Thanks in advance

like image 531
TheNone Avatar asked Aug 05 '26 21:08

TheNone


2 Answers

You need either the jQuery color plugin or jQuery UI (which includes the same functionality) to animate colors.

As an example: here's your fiddle with jQuery UI included (only change) to see it working.

like image 163
Nick Craver Avatar answered Aug 08 '26 11:08

Nick Craver


The animate() function in jQuery will only animate numerical css properties. The value of the color property is not numeric. In order to animate the color property you'll need to include jQuery ui, or another lighter weight plugin as Nick mentioned, which will extend the jQuery object to have that functionality.

http://api.jquery.com/animate/ explains it all.

like image 29
Pizano Avatar answered Aug 08 '26 10:08

Pizano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!