Skip to content

Commit cd7a6eb

Browse files
committed
js timers
1 parent c2308e0 commit cd7a6eb

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

js-timers/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# JavaScript Timers
2+
3+
> [http://youtu.be/YmaFAKUFmp0](http://youtu.be/YmaFAKUFmp0)
4+
5+
Install [io.js](https://iojs.org/en/index.html).
6+
7+
Within this folder run the terminal command `npm install` to install the
8+
`devDependencies`.
9+
10+
Then run `npm start` to start up a development server on `http://localhost:9966`

js-timers/bear.jpg

61.8 KB
Loading

js-timers/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// setTimeout(function () {
2+
// console.log('im called after 1s');
3+
// }, 1000);
4+
5+
// var count = 0;
6+
// var interval = setInterval(function () {
7+
// if (count > 5) {
8+
// clearInterval(interval);
9+
// }
10+
// count++;
11+
// console.log('every 1s');
12+
// }, 1000);
13+
14+
// function getBear (callback) {
15+
// setTimeout(function () {
16+
// console.log('got bear');
17+
// callback();
18+
// }, 3000 * Math.random());
19+
// }
20+
//
21+
// function poll () {
22+
// getBear(function () {
23+
// setTimeout(poll, 1000);
24+
// });
25+
// }
26+
// poll();
27+
28+
var bear = new Image();
29+
bear.src = '/bear.jpg';
30+
bear.style.position = 'absolute';
31+
document.body.appendChild(bear);
32+
33+
var delta = 0;
34+
var amount = 50;
35+
function draw () {
36+
bear.style.left = amount * Math.sin(delta) + 'px';
37+
delta += .1;
38+
requestAnimationFrame(draw);
39+
}
40+
draw();

js-timers/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "js-timers",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js"
8+
},
9+
"author": "Kyle Robinson Young <kyle@dontkry.com> (http://dontkry.com)",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"budo": "^4.2.1"
13+
}
14+
}

0 commit comments

Comments
 (0)