Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery animate .css

I have a script:

$('#hfont1').hover(     function() {         $(this).css({"color":"#efbe5c","font-size":"52pt"}); //mouseover     },      function() {         $(this).css({"color":"#e8a010","font-size":"48pt"}); // mouseout     } ); 

how can i animate it or slow it down, so it wont be instant ?

like image 584
Plaski Avatar asked Dec 03 '10 15:12

Plaski


People also ask

How do you animate in jQuery?

The jQuery animate() method is used to create custom animations. Syntax: $(selector).animate({params},speed,callback);

Can the animate () method be used to animate any CSS property?

The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px").

How you can use jQuery to animate a flash to the button?

Pure jQuery solution. var flash = function(elements) { var opacity = 100; var color = “255, 255, 20” // has to be in this format since we use rgba var interval = setInterval(function() { opacity -= 3; if (opacity How can use jQuery to animate a flash to the button? var randomNumber = Math. floor(Math.

How do you animate with relative values?

To change the left or right or top or bottom of an element with a relative value, we use +=value or -=value in the CSS property, so that it changes the value at the current position to the relative increment or decrement with respect to the current position with the value given in the CSS property. $('selector').


2 Answers

Just use .animate() instead of .css() (with a duration if you want), like this:

$('#hfont1').hover(function() {     $(this).animate({"color":"#efbe5c","font-size":"52pt"}, 1000); }, function() {     $(this).animate({"color":"#e8a010","font-size":"48pt"}, 1000); }); 

You can test it here. Note though, you need either the jQuery color plugin, or jQuery UI included to animate the color. In the above, the duration is 1000ms, you can change it, or just leave it off for the default 400ms duration.

like image 191
Nick Craver Avatar answered Sep 30 '22 11:09

Nick Craver


You could opt for a pure CSS solution:

#hfont1 {     transition: color 1s ease-in-out;     -moz-transition: color 1s ease-in-out; /* FF 4 */     -webkit-transition: color 1s ease-in-out; /* Safari & Chrome */     -o-transition: color 1s ease-in-out; /* Opera */ } 
like image 34
blend Avatar answered Sep 30 '22 11:09

blend