I have some bars that are filled with a height %, but right when the page loads I would like all the bars to fill up and then decrease to 0. I know how to fill it up with a for
dude slideToggle. Check it - http://jsfiddle.net/6hp2G/. works like a boss
I think jQuery animate is what you are looking for. Result is something like this.
You're looking for:
for(i = 100; i >= 0; i--)
But you could just do this slideUp:
$('someElement')
.hide()
.slideDown(500, function () {
$(this).slideUp(500);
});
The above would animate the element like you want. That code equates to roughly the following, in case you even want to do more complicated animate animations:
$('someElement')
.hide()
.animate({ height: '100%' }, 500, function () {
$(this).animate({ height: 0 }, 500);
});
Update: Here is a jsFiddle demonstration.
the second one should be:
for(i = 100; i >= 0; i--)
How about this:
for(i = 100; i >= 0; i--)
If you are trying to animate the height of an object then I think you want the .animate()
function of jQuery:
$('.bar-elements').animate({ height : '100%' }, 1500, function () {
$(this).animate({ height : 0 }, 1500);
});
or alternatively you can use the slideUp
/slideDown
functions that do this already:
$('.bar-elements').hide().slideDown(1500, function () {
$(this).slideUp(1500);
});
Docs for .animate()
: http://api.jquery.com/animate
Docs for .slideUp()
: http://api.jquery.com/slideup