I'm trying to make a count up animation in Javascript. That is to say, the animation would start at 0, then, given an animation duration, count up to a given number. Is this possible in Javascript?
Additionally, is it possible to have the animation play only once the user scrolls down to that point on the page?
-
3You're trying. That is to say you've done some work. May we see it?David G– David G2012-08-25 12:13:38 +00:00Commented Aug 25, 2012 at 12:13
-
So far, I haven't actually got anything.Jules– Jules2012-08-25 12:17:58 +00:00Commented Aug 25, 2012 at 12:17
-
1What are you 'animating'? Images of the numbers, the numbers themselves (as text)? Something else?David Thomas– David Thomas2012-08-25 12:20:39 +00:00Commented Aug 25, 2012 at 12:20
-
They're numbers, as in actual type.Jules– Jules2012-08-25 12:22:11 +00:00Commented Aug 25, 2012 at 12:22
Add a comment
|
2 Answers
Have you tried taking a look at the setInterval(func, delay[, param1, param2, ...]) method?
From Mozilla Developer Network:
Calls a function or executes a code snippet repeatedly, with a fixed time delay between each call to that function.
To illustrate how to use the setInterval method to create a simple counter that starts counting at 0 and increments every second, I have created this jsFiddle: http://jsfiddle.net/zrccC/ - the sample also illustrates how to clear the timer.
1 Comment
David G
I think you should give him an MDN link instead of a W3Schools link.