• <small id='qwi4F'></small><noframes id='qwi4F'>

  • <legend id='qwi4F'><style id='qwi4F'><dir id='qwi4F'><q id='qwi4F'></q></dir></style></legend>

      1. <i id='qwi4F'><tr id='qwi4F'><dt id='qwi4F'><q id='qwi4F'><span id='qwi4F'><b id='qwi4F'><form id='qwi4F'><ins id='qwi4F'></ins><ul id='qwi4F'></ul><sub id='qwi4F'></sub></form><legend id='qwi4F'></legend><bdo id='qwi4F'><pre id='qwi4F'><center id='qwi4F'></center></pre></bdo></b><th id='qwi4F'></th></span></q></dt></tr></i><div id='qwi4F'><tfoot id='qwi4F'></tfoot><dl id='qwi4F'><fieldset id='qwi4F'></fieldset></dl></div>
          <bdo id='qwi4F'></bdo><ul id='qwi4F'></ul>
        <tfoot id='qwi4F'></tfoot>

        在画布中制作可点击区域以更改图像

        时间:2023-06-20
          <tfoot id='gmpHe'></tfoot>
          <i id='gmpHe'><tr id='gmpHe'><dt id='gmpHe'><q id='gmpHe'><span id='gmpHe'><b id='gmpHe'><form id='gmpHe'><ins id='gmpHe'></ins><ul id='gmpHe'></ul><sub id='gmpHe'></sub></form><legend id='gmpHe'></legend><bdo id='gmpHe'><pre id='gmpHe'><center id='gmpHe'></center></pre></bdo></b><th id='gmpHe'></th></span></q></dt></tr></i><div id='gmpHe'><tfoot id='gmpHe'></tfoot><dl id='gmpHe'><fieldset id='gmpHe'></fieldset></dl></div>
                <legend id='gmpHe'><style id='gmpHe'><dir id='gmpHe'><q id='gmpHe'></q></dir></style></legend>
                • <bdo id='gmpHe'></bdo><ul id='gmpHe'></ul>

                  <small id='gmpHe'></small><noframes id='gmpHe'>

                    <tbody id='gmpHe'></tbody>
                  本文介绍了在画布中制作可点击区域以更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  请帮帮我:

                  • 在下面的画布中创建可点击区域,我可以将 onmousedown= 事件分配给这些区域.我知道如何用不可见的 DIV 做到这一点,但我认为有一种更优雅的方式可以在我不知道的画布中做到这一点.

                  • create clickable regions in the canvas below that I can assign onmousedown= events to. I know how to do this with invisible DIVs, but I think there is a more elegant way to do it in canvas that I don't know.

                  当我单击其中一个区域时,想要将图像名称传递给函数,以便它将正在显示的图像更改为另一个图像,然后将其更改回 onmouseup.

                  when I click one of the regions, want to pass an image name to a function so that it changes the image being displayed to another image, and then changes it back onmouseup.

                  如果您只给我展示一个区域和一个 mousedown/mouseup 示例,我可以完成剩下的...谢谢.

                  if you show me just one region and one mousedown/mouseup example I can do the rest...thanks.

                  <!DOCTYPE HTML>
                  <html>
                  <head>
                  </head>
                  <body>
                  
                          <canvas id="myCanvas" width="506" height="319" style="border:1px solid #c3c3c3;">
                          Your browser does not support the canvas element.
                          </canvas>
                  
                          <script type="text/javascript">
                          var c=document.getElementById("myCanvas");
                          var ctx=c.getContext("2d");
                          var img=new Image();
                          img.onload = function(){
                          ctx.drawImage(img,0,0);
                          };
                          img.src="firstImage.gif";
                          </script>
                  
                          /////////HERE NEED/////////
                                      CREATE CLICKABLE REGION <region>
                                      <region>
                                      onmousedown=changeCanvasImage(secondImage.gif) //change image on click
                                      onmouseup=changeCanvasImage(firstImage.gif)  /change it back when done
                          </region>
                  </body>
                  </html>
                  

                  推荐答案

                  canvas 元素可以触发事件,但canvas 中的图形元素不能.为此,您需要通过检测 鼠标在画布上的位置,当它被单击并将值与画布中的某些内容相关联时,或者使用许多 canvas 库可用于处理为您检测.

                  The canvas element can fire events but graphical elements within the canvas cannot. To do this you'll either need to implement it yourself by detecting the position of the mouse on the canvas when it is clicked and relating the value to something in your canvas, or using one of the many canvas libraries available which will handle the detection for you.

                  这篇关于在画布中制作可点击区域以更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:HTML5 画布调整为父级 下一篇:如何在画布中填充图案并沿形状弯曲?

                  相关文章

                • <legend id='0SEJK'><style id='0SEJK'><dir id='0SEJK'><q id='0SEJK'></q></dir></style></legend>
                    <tfoot id='0SEJK'></tfoot>

                      <i id='0SEJK'><tr id='0SEJK'><dt id='0SEJK'><q id='0SEJK'><span id='0SEJK'><b id='0SEJK'><form id='0SEJK'><ins id='0SEJK'></ins><ul id='0SEJK'></ul><sub id='0SEJK'></sub></form><legend id='0SEJK'></legend><bdo id='0SEJK'><pre id='0SEJK'><center id='0SEJK'></center></pre></bdo></b><th id='0SEJK'></th></span></q></dt></tr></i><div id='0SEJK'><tfoot id='0SEJK'></tfoot><dl id='0SEJK'><fieldset id='0SEJK'></fieldset></dl></div>
                        <bdo id='0SEJK'></bdo><ul id='0SEJK'></ul>

                      <small id='0SEJK'></small><noframes id='0SEJK'>