<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TEST</title>
</head>
<body>
<canvas id="backcanvas" width="200px" height="100px" style="position:fixed;top:0px;left:0px;"></canvas>
<canvas id="frontcanvas" width="200px" height="100px" style="position:fixed;top:0px;left:0px;"></canvas>
<script>
var interval,frontCanvas,backCanvas,frontCtx,backCtx,img;
var yFrontPosition = 0,step = 2,canvasWidth,canvasHeight;
var canvasX = 0,canvasY=0;
window.onload = function(){
initPageEle();
drawImg();
startrun();
}
function drawImg(){
img=new Image();
img.src = "Tulips.jpg";
img.onload = loadImg;
}
function initPageEle(){
frontcanvas = document.getElementById("frontcanvas");
backCanvas = document.getElementById("backcanvas");
frontCtx = frontcanvas.getContext("2d");
backCtx = backCanvas.getContext("2d");
canvasWidth = backCanvas.width ;
canvasHeight = backCanvas.height;
backCtx.fillStyle = 'rgba(255, 255, 255, 0)';
backCtx.strokeStyle = "#24303a";
backCtx.lineWidth = 2;
frontCtx.fillStyle = 'rgba(255, 255, 255, 0)';
frontCtx.strokeStyle = "white";
frontCtx.lineWidth = 2;
}
function loadImg(){
backCtx.drawImage(img,0,0,canvasWidth,canvasHeight);
drawBackground();
}
function startrun(){
interval = setInterval(draw,100);
}
function draw(){
drawFront();
}
function drawFront(){
yFrontPosition = yFrontPosition+step;
frontCtx.fillRect(canvasX,canvasY,canvasWidth,canvasHeight);
frontCtx.clearRect(canvasX,canvasY,canvasWidth,canvasHeight);
frontCtx.beginPath();
frontCtx.moveTo(canvasX,yFrontPosition);
frontCtx.lineTo(canvasWidth,yFrontPosition);
frontCtx.stroke();
frontCtx.closePath();
if(yFrontPosition>=canvasHeight){
yFrontPosition = canvasX;
}
}
function drawBackground(){
backCtx.fillStyle = "#24303a";
backCtx.globalAlpha = 0.4;
backCtx.beginPath();
backCtx.moveTo(canvasX,canvasY);
backCtx.lineTo(canvasX+canvasWidth,canvasY);
backCtx.lineTo(canvasX+canvasWidth,canvasY+canvasHeight);
backCtx.lineTo(canvasX,canvasY+canvasHeight);
backCtx.lineTo(canvasX,canvasY);
backCtx.fill();
backCtx.closePath();
backCtx.stroke();
}
function stop(){
clearInterval(interval);
}
</script>
<html>
<head>
<meta charset="UTF-8">
<title>TEST</title>
</head>
<body>
<canvas id="backcanvas" width="200px" height="100px" style="position:fixed;top:0px;left:0px;"></canvas>
<canvas id="frontcanvas" width="200px" height="100px" style="position:fixed;top:0px;left:0px;"></canvas>
<script>
var interval,frontCanvas,backCanvas,frontCtx,backCtx,img;
var yFrontPosition = 0,step = 2,canvasWidth,canvasHeight;
var canvasX = 0,canvasY=0;
window.onload = function(){
initPageEle();
drawImg();
startrun();
}
function drawImg(){
img=new Image();
img.src = "Tulips.jpg";
img.onload = loadImg;
}
function initPageEle(){
frontcanvas = document.getElementById("frontcanvas");
backCanvas = document.getElementById("backcanvas");
frontCtx = frontcanvas.getContext("2d");
backCtx = backCanvas.getContext("2d");
canvasWidth = backCanvas.width ;
canvasHeight = backCanvas.height;
backCtx.fillStyle = 'rgba(255, 255, 255, 0)';
backCtx.strokeStyle = "#24303a";
backCtx.lineWidth = 2;
frontCtx.fillStyle = 'rgba(255, 255, 255, 0)';
frontCtx.strokeStyle = "white";
frontCtx.lineWidth = 2;
}
function loadImg(){
backCtx.drawImage(img,0,0,canvasWidth,canvasHeight);
drawBackground();
}
function startrun(){
interval = setInterval(draw,100);
}
function draw(){
drawFront();
}
function drawFront(){
yFrontPosition = yFrontPosition+step;
frontCtx.fillRect(canvasX,canvasY,canvasWidth,canvasHeight);
frontCtx.clearRect(canvasX,canvasY,canvasWidth,canvasHeight);
frontCtx.beginPath();
frontCtx.moveTo(canvasX,yFrontPosition);
frontCtx.lineTo(canvasWidth,yFrontPosition);
frontCtx.stroke();
frontCtx.closePath();
if(yFrontPosition>=canvasHeight){
yFrontPosition = canvasX;
}
}
function drawBackground(){
backCtx.fillStyle = "#24303a";
backCtx.globalAlpha = 0.4;
backCtx.beginPath();
backCtx.moveTo(canvasX,canvasY);
backCtx.lineTo(canvasX+canvasWidth,canvasY);
backCtx.lineTo(canvasX+canvasWidth,canvasY+canvasHeight);
backCtx.lineTo(canvasX,canvasY+canvasHeight);
backCtx.lineTo(canvasX,canvasY);
backCtx.fill();
backCtx.closePath();
backCtx.stroke();
}
function stop(){
clearInterval(interval);
}
</script>
</body>