Skip to content

Instantly share code, notes, and snippets.

@suneo3476
Created June 17, 2013 18:10
Show Gist options
  • Save suneo3476/5798906 to your computer and use it in GitHub Desktop.
Save suneo3476/5798906 to your computer and use it in GitHub Desktop.
要素がsetIntervalでアニメーションする。
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>アニメーション</title>
</head>
<body>
<div id="foo" style="position: absolute">This is sample.</div>
<script>
var elem = document.getElementById('foo');
var frame = 0;
setInterval(function () {
frame += 1;
elem.style.left = frame * 10 + 'px';
}, 100); // 100ミリ秒ごとに10ピクセルずつ右に移動していく
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment