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 ?
The jQuery animate() method is used to create custom animations. Syntax: $(selector).animate({params},speed,callback);
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").
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.
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').
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.
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 */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With