Reputation: 1820
I am trying to fade all anchor links colors in and our on mouseenter and mouseleave. This is my best effort so far.
$(document).ready(function(){
$('a').on('mouseenter' , function(){
$(this).toggle(function (){
animate({color:"#ee860a"})
});
}
);
});
actually that my best effort was without the toggle function, which might not be appropriate here. Do I need to make 2 functions? 1 with mouseenter and 1 with mouseleave? Or is it best/possible to do with toggle?
Upvotes: 0
Views: 902
Reputation: 6406
You need a jQuery plugin to animate colors: https://github.com/jquery/jquery-color
I prefer using a CSS3 solutin:
a{
-moz-transition: all 0.5s;
-webkit-transition: all 0.5s;
transition: all 0.5s;
color:#000;
}
a:hover{
color:#ee860a;
}
Upvotes: 0
Reputation: 21
$(document).ready(function(){
$('a').hover(function(){
$(this).animate({color:"#ee860a"});
}, function() {
$(this).animate({color:"#999"});
});
});
Try this :)
Upvotes: 2
Reputation: 11812
Your syntax is wrong. animate
is used like this:
$(document).ready(function(){
$('a').on('mouseover' , function(){
$(this).animate({color:"#ee860a"},'slow');
});
});
See this fiddle: http://jsfiddle.net/ZtBpM/1/
Your approach for the mouseout
(rather use this than mouseleave
- same goes for mouseover
instead of mouseenter
) is ok (just do the same thing with a different event), although you could also use hover
http://api.jquery.com/hover/ which will allow you to bind the functions for mouseover and mouseout in a single call.
Upvotes: 1
Reputation: 4974
Insert http://www.bitstorm.org/jquery/color-animation/jquery.animate-colors-min.js below jQuery and add the follow code to your element:
$('#elementToEffect').animate({color: '#ee860a'})
Upvotes: 0