question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onMouseOver() event triggered multiple times

See original GitHub issue

I add the mouseover handler to Stage, but found the handler called multiple times even when the mouse pointer is only moving inside the canvas. It’s not like the example: https://konvajs.org/docs/events/Image_Events.html . Any clue?

onMouseOver(e) {
    if (e.target.attrs.x === undefined) {
      return;
    }

    let p = this.getPointFromEvent(e);
    console.log(p.x);
    // alert(p.x);

    if (p.x < 0 || p.x > gridX - 1 || p.y < 0 || p.y > gridY - 1) {
      return;
    }

    this.setState({
      hoverPiece: {x: p.x, y: p.y}
    });
  }

render() {
    return (
      <div>
        <Col span={8}>
          <Stage width={500} height={300} onClick={this.onClick.bind(this)} onMouseOver={this.onMouseOver.bind(this)} onMouseOut={this.onMouseOut.bind(this)}>
            <Layer>
              {
                this.renderGrid()
              }
              {/*<Text text="Some text on canvas" fontSize={15} />*/}
              {/*<Rect*/}
              {/*  x={20}*/}
              {/*  y={50}*/}
              {/*  width={100}*/}
              {/*  height={100}*/}
              {/*  stroke={"black"}*/}
              {/*  strokeWidth={4}*/}
              {/*  // fill="red"*/}
              {/*  // shadowBlur={10}*/}
              {/*/>*/}

              {
                this.renderPieces()
              }
              {/*<LionImage />*/}

              <Line
                points={this.getPoints()}
                stroke="black"
                strokeWidth={10}
              />
              {
                this.renderHighlight()
              }
            </Layer>
          </Stage>
        </Col>
      
      </div>

    );
  }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lavrtoncommented, Nov 26, 2019

You can set listening={false} to background rectangle. So it doesn’t affect hit regions and events.

0reactions
lavrtoncommented, Oct 29, 2020

This is how mouseover event works. I think you want mouseenter instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mouseover and mouseout trigger multiple times - Stack Overflow
entering means when your cursor enters the bounds of the element. Even when you are in a child node, you are still within...
Read more >
Onmouseover/out fireing multiple times? - JavaScript - SitePoint
When I run my mouse over the DIV Object in inquestion, it fire's off several times. Does anyone know what might cause such...
Read more >
Javascript – Mouseover and mouseout trigger multiple times
entering means when your cursor enters the bounds of the element. Even when you are in a child node, you are still within...
Read more >
onmouseover Event - W3Schools
The onmouseover event occurs when the mouse pointer enters an element. The onmouseover event is often used together with the onmouseout event, which...
Read more >
D3 circle pack layout mouseover event is getting triggered ...
... pack layout mouseover event is getting triggered multiple times-d3.js. ... const updateGraph = graphData => { const pack = data => d3.pack()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found