2

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?

4
  • 3
    You're trying. That is to say you've done some work. May we see it? Commented Aug 25, 2012 at 12:13
  • So far, I haven't actually got anything. Commented Aug 25, 2012 at 12:17
  • 1
    What are you 'animating'? Images of the numbers, the numbers themselves (as text)? Something else? Commented Aug 25, 2012 at 12:20
  • They're numbers, as in actual type. Commented Aug 25, 2012 at 12:22

2 Answers 2

2
(function (e) {
    setTimeout(function () {
         e += 1;
    }, 1000).call(this, 0);

It counts, after all?

Sign up to request clarification or add additional context in comments.

Comments

0

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.

See: https://developer.mozilla.org/en-US/docs/DOM/window.setInterval?redirectlocale=en-US&redirectslug=window.setInterval

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

I think you should give him an MDN link instead of a W3Schools link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.