I trying to add the text effect using jquery with ui animate
. Is there is a way to show all possible color randomly without defined all colors. For example color combination is based on RGB
.
Using the animate with color like
setInterval(function() {
jQuery(".font-style").animate({color: "red"}, 2000).
animate({color: "green"}, 2000).animate({color: "blue"}, 2000);}, 400);
Is there is any possibilities to show the color combination of RGB
Randomly in jquery. Any suggestion would be great.
Thanks.
You can generate a random color like this:
var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
jQuery(".font-style").animate({color: newColor}, 2000); // animate
This will create a random hex color such as #ff00cc.
Note: regular jQuery doesn't animate colors, you'll have to use jQuery color plugin or jQuery UI
You could do something like this:
var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
And than put col
in your animate:
jQuery(".font-style").animate({color: col}, 2000)
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