Jump to content
  • 0

Нажатие на картинку Canvas


Ser8191
 Share

Question

Уважаемые мастера, подскажите:

<!DOCTYPE html>
<html>
<head>
<title>Canvas from scratch</title>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");

var lverx = document.getElementById("lverx");
lverx.onload = function() {   
ctx.drawImage(lverx, 0, 0, 200, 83);
}

var pverx = document.getElementById("pverx");
pverx.onload = function() {   
ctx.drawImage(pverx, 200, 0, 200, 83);
}

var lniz = document.getElementById("lniz");
lniz.onload = function() {   
ctx.drawImage(lniz, 0, 83, 200, 83);
}

var pniz = document.getElementById("pniz");
pniz.onload = function() {   
ctx.drawImage(pniz, 200, 83, 200, 83);
}

});
</script>
</head>

<body>
<canvas id="myCanvas" width="400" height="200"></canvas>
<img id="lverx" src="01.png" style="display:none;" />
<img id="pverx" src="02.png" style="display:none;" />
<img id="lniz" src="03.png" style="display:none;" />
<img id="pniz" src="04.png" style="display:none;" />
</body>
</html>

Как при нажатии на, к примеру, эту

var lverx = document.getElementById("lverx");
lverx.onload = function() {   
ctx.drawImage(lverx, 0, 0, 200, 83);

картинку выполнить нужную функцию и заменить эту картинку на другую.

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy