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.
This can be done using span changing its width over the time. Here is the working fiddle. The code is displayed below. Only the mandatory styles are displayed here.
HTML
CSS
jQuery
Background gradient loader - possibly more appropriate
You could also use the background gradient as the loader. Of course, jQuery doesn't natively support choosing correct CSS prefixes, so it may have to be tweeked to work in older browsers. But it'll work nicely where your browser supports
linear-gradient
.Since jQuery won't animate a background gradient, I've animated a span within it and am using the
step
option to change the gradient stops each time. This means that anyduration
oreasing
changes to theanimate()
will apply to the gradient as well:JSFiddle
Original answer
background-color
is the CSS style, you are targeting the property of the javascript object, which in this case, isbackgroundColor
. You'll want to change the color name as well.JSFiddle
backgroundColor
.'red'
, so it will not change anything. Change the string to'blue'
.If you are able to use latest CSS (which mean no stupid old browser), you may use CSS3's gradient function
Example at: http://jsfiddle.net/hkdennis2k/ebaF8/2/
You need to use the jQuery.Color() plugin for background-color animation.
I thought your looking for a "Progress Bar Animation"? try this: i believe its what your looking for - the progress bar's horizontal loading motion in a jsfiddle here:
http://jsfiddle.net/c78vF/6/
with a few more elements you are able to simulate that easily using the same tech everyone else is using here... jquery ui etc
html:
css:
js: