Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
williamrossi
6,232 Pointsanimating from 0 to 100
Hi all I am trying to get some smooth animations going, I want to have 0 and on page load it quickly count up to 100.
how would I do this?
3 Answers
Chris Shaw
26,676 PointsHi williamrossi,
See the below fiddle I created quickly, it's a very basic example of using an interval to achieve the desired result, the nicer way of doing this would be to use the requestAnimationFrame callback but for the purposes of this demo setInterval will suffice.
williamrossi
6,232 PointsLooks ideal! Thanks Chris
Chris Shaw
26,676 PointsNo worries, when you replied I had a clear mind and thought about the progress element which overall is much nicer to use but of course carries an IE10+ and modern browser restriction.
williamrossi
6,232 PointsThanks again I would not be able to write something like this from scratch, I can read it just about and I understand what it is doing but could you tell me a few things..
what are the [0] 's doing, is that picking the first 'div' and 'span' it finds? and what is the 2000 / 100 part? is that just the timing?
and also is there a way to generate random numbers first? I have a another screen where I want to have a number generate anything between 0-500 and after about 4 random numbers it lands on 500 and stays there are a few seconds.
thanks again
Hugo Paz
15,622 PointsHugo Paz
15,622 PointsAre you looking at a loading bar or a simple counter?