• <bdo id='BbdpP'></bdo><ul id='BbdpP'></ul>

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

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

      <legend id='BbdpP'><style id='BbdpP'><dir id='BbdpP'><q id='BbdpP'></q></dir></style></legend>
    2. <tfoot id='BbdpP'></tfoot>

        如何在 html5 画布中制作可点击点?

        How to make clickable points in html5 canvas?(如何在 html5 画布中制作可点击点?)

              <bdo id='rp2Xr'></bdo><ul id='rp2Xr'></ul>
            • <small id='rp2Xr'></small><noframes id='rp2Xr'>

              <tfoot id='rp2Xr'></tfoot>

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

                  本文介绍了如何在 html5 画布中制作可点击点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在玩 简单教程 用于在 HTML5 画布中绘制线条.因为它是基于jQuery的,所以很容易给绘图添加很多效果.

                  I am playing with a simple tutorial for drawing line in HTML5 canvas. Since, it is based on jQuery, it is easy to add lots of effects to the drawing.

                  如何使点可单击/悬停以在单击/悬停时添加 jquery 效果(mouseenter/mouseleave)?点是由

                  How can I make the point clickable/hoverable to add jquery effects upon click/hover (mouseenter/mouseleave)? The points are drawn by

                  c.fillStyle = '#333';
                  
                  for(var i = 0; i < data.values.length; i ++) {
                      c.beginPath();
                      c.arc(getXPixel(i), getYPixel(data.values[i].Y), 4, 0, Math.PI * 2, true);
                      c.fill();
                  }
                  

                  如何添加 jquery 选择器?基本上,我想在点击或悬停时显示点坐标.

                  How to add jquery selector? Basically, I want to show the point coordinates upon click or hover.

                  推荐答案

                  问题是 jQuery 使用 DOM 而不是画布上的绘图.您需要做的是将这些点存储在某处并将鼠标悬停在画布元素上,检查鼠标相对于画布的坐标(即,如果您将鼠标放在画布的左上角,坐标是 [0,0] )在点/形状的区域内.如果是这样,鼠标悬停在该点上即可显示效果.

                  The problem is that jQuery works with DOM and not drawings on canvas. What you need to do is to store those points somewhere and on hovering over the canvas element, check if the coordinates of the mouse relative to the canvas ( i.e. if you place the mouse over the top-left corner of the canvas, coords are [0,0] ) are within the area of the point/shape. If so, the point is hovered over by the mouse and you can display the effect.

                  为了更好地理解伪代码:

                  Psuedocode to understand better:

                  // adding shapes to the canvas
                  var shapes = [];  // make that rects for simplicity.
                  For (condition):
                      shapes.push ( new Rect(x,y,width,height) );
                      canvas.rect( x, y, width, height );
                  
                  // testing hover.
                  $("#canvas").mousemove(function(e) {
                      var offsetX = e.pageX - $(this).position().left;
                      var offsetY = e.pageY - $(this).position().top;
                  
                      Foreach shape in shapes:
                          if( shape.contains(offsetX, offsetY) )    // a fictious method, implement it yourself...lookup for collision detection; not exactly that but something like that...
                              Mouse hovers! do something great.
                  });
                  

                  好吧,也许要找出一个点是否包含在一个矩形内,你可以使用这样的东西:

                  Ok, maybe to find out if a point is contained within a rectangle, you can use something like this:

                  function contains(rect, x, y) {
                      return (x >= rect.x &&
                              x <= rect.x + rect.width &&
                              y >= rect.y && 
                              y <= rect.y + rect.height )
                  }
                  

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)

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

                          <tbody id='whc9W'></tbody>

                        <tfoot id='whc9W'></tfoot>
                      1. <small id='whc9W'></small><noframes id='whc9W'>

                        • <legend id='whc9W'><style id='whc9W'><dir id='whc9W'><q id='whc9W'></q></dir></style></legend>
                            <bdo id='whc9W'></bdo><ul id='whc9W'></ul>