<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CANVAS 연습</title>
</head>
<body>
<canvas id="myCanvas" width="800" height="600" style="border: 1px dotted red"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var bgImage = new Image(); //이미지 선언
bgImage.src = "https://t1.daumcdn.net/cfile/tistory/99664A3B5B35D3182C"; //이미지 경로 설정
var x = 0; //x좌표 초기화
function animate() {
ctx.drawImage(bgImage, x--, 0, 2400, 600); //이미지를 불러와 화면에 그린다.
if (x <= -1600) { // 이미지가 끝까지 지나갔을 때 x 좌표값을 초기화 한다
x = 0;
}
}
var animateInterval = setInterval(animate, 30); // 30ms 간격으로 animate 함수 실행
</script>
</body>
</html>