Jump to content

images in javascript canvas don't display properly

stefanmz

Hey, so I have a canvas with javascript where I display an image but the image doesn't always load,sometimes I have to refresh the page for the image to load. Why is that?

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="author" content="Stefan Zapryanov">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" type="text/css" href="Styles.css">
	<title>Java Script Worship</title>
</head>
<body>
	<img id="js" alt="js logo" src="js.png">
	<canvas id="Java" width="350" height="390"></canvas>
	<script type="text/javascript">
		var canvas=document.getElementById('Java');
		var draw=canvas.getContext("2d");
		draw.beginPath();
		draw.rect(70,120,200,200);
		draw.fillStyle="rgba(241,218,78,255)";
		draw.fill();
		var text=canvas.getContext("2d");
		text.fillStyle="rgba(2,2,2,255)";
		text.font="44px Tahoma";
		text.fillText("I love JavaScript",15,70);
		var drawimage=canvas.getContext("2d");
		var image=document.getElementById("js");
		drawimage.drawImage(image,130,215);

		


	</script>
</body>
</html>

 

canvas{
	margin-top: 5px;
	border: 5px solid transparent;
	border-image: url('frame.png') 160;
	border-image-width: 350px;
	border-image-repeat: repeat;
    border-image-outset: 17px;

}
img{
	display: none;
}
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×