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.

How to position in the mouse click?

See original GitHub issue

I finally managed to position using pure popper a div inside a SVG. I wish to do the same with tippy

I’m trying the following approach which does not work:

  select(e: MouseEvent) {
    const ref = {
      getBoundingClientRect() {
        return {
          width: e.layerY,
          height: e.layerX,
          top: e.layerY,
          left: e.layerX,
          right: 0,
          bottom: 0
        }
      },
      clientHeight: 100,
      clientWidth: 100
    }

    tippy('.line', {
      target: 'polyline',
      trigger: 'click',
      arrow: true
    }, ref);
  }

This worked with popper:

  select(e: MouseEvent) {
    const ref = {
      getBoundingClientRect: () => ({
        top: e.layerY,
        right: e.layerX,
        bottom: e.layerY,
        left: e.layerX,
        width: 0,
        height: 0,
      }),
      clientWidth: 0,
      clientHeight: 0,
    }
    
    const pop = document.getElementById('template'); // the popup element

    this.popper = new Popper(ref, pop);    
  } 

What am I missing?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
atomikscommented, Aug 12, 2018

Yeah, you need to use the object as the actual reference itself.

But I see that you want to use the line as the reference for tippy to handle listeners for, but want a custom position where they clicked… that’s a really valid use case that hasn’t been added yet 😢 .

0reactions
atomikscommented, Sep 13, 2019

This was fixed in Dec 2018 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting the Mouse Click Position in JavaScript | kirupa.com
You want the X and Y position based on the top-left (aka the starting position) corner of your document. It is this value...
Read more >
javascript get x and y coordinates on mouse click
Creates (undefined) variables for the X and Y coordinates of the mouse; Attaches a function to the "mousemove" event (which will set those ......
Read more >
JavaScript: Get Mouse Coordinates on Mouse Click - YouTube
JavaScript Keyboard Events: Difference between Keydown, Keyup and Keypress Events · Move Element to Mouse Click Position · getBoundingClientRect() ...
Read more >
Mouse and Keyboard Controls
Ctrl - right mouse button click: Zoom down around the clicked point. Left mouse button drag: Holding the left button down and moving...
Read more >
Position of mouse pointer does not match screen coordinates ...
Open control panel > Hardware & Sound. · Click on Mouse. · In mouse properties, click on pointer option tab. · Decrease the...
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