I have a div which has some text content( eg: My Name ) and the div is in RED background colour
and a button.
My need :
If I have clicked the button , I need to change the background of a div from RED to BLUE like Progress bar
for 10 seconds.Something like,
start from 0 sec
=
==
===
====
=====
======
=======
========
=========
==========
end with 10 seconds
I have to change the bgColor gradually from start to end for upto 10 secs.
So I have used the JQuery animate() method .But I have no luck to do that.
What I have tried :
$("button").click(function(){
$('#myDivId').animate({background-color:'blue'},10000);
});
If this is not possible , can anyone please suggest me some plugin's to do that.
Hope our stack users will help me.
try below code
And Let me know it's working or not...waiting for your reply .......
you can use this code:
jsFiddle is here
HTML:
CSS:
JQuery:
Any particular reason you want to do this in jQuery as opposed to css3?
Bootstrap has a pretty nifty way of achieving this -> http://getbootstrap.com/components/#progress-animated
The .progress-bar class has a css3 transition set on the width property, so as you move between 0% & 100%, any updates to the width are smoothly animated. It also uses a css3 animation to animate the background gradient (striped pattern).
Or you could do the math and do the color change. http://jsfiddle.net/rustyDroid/WRExt/2/
Furthemore of the previus coments (change background-color for backgroundColor) you also need the plugin Jquery Colors, I made a test and without it don't work.
Put this on the head: