0

In my application I use KonvaJS extensively, but I reached a step where I need to create a Bootstrap Popover on KonvaJS Image click, is that possible?

Please note that I have more than 50 images in this app and I need to create a popover for each.

Mahdi Alkhatib
  • 1,954
  • 1
  • 29
  • 43
  • What did you try? You can get mouse position on click? And you can create popover and then overwrite position (with mouse position). http://codingexplained.com/coding/front-end/css/change-bootstrap-popover-position – lavrton Jun 30 '16 at 03:55

1 Answers1

1

If you want to have PopOver only for canvas images then I would suggest to use Konva.Label. You can set the pointer in whichever direction you want and set the position of label. Here's the plunkr which I have created.

<!DOCTYPE html>
<html>

<head>
  <script src="https://cdn.rawgit.com/konvajs/konva/0.15.0/konva.min.js"></script>
  <meta charset="utf-8">
  <title>Konva Label Demo</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      overflow: hidden;
      background-color: #F0F0F0;
    }
  </style>
</head>

<body>
  <div id="container"></div>
  <script>
    var stage = new Konva.Stage({
      container: 'container',
      width: 300,
      height: 300
    });

    var layer = new Konva.Layer();
    // label with left pointer
    var tooltip = new Konva.Label({
      x: 170,
      y: 75,
      opacity: 0.75
    });

    tooltip.add(new Konva.Tag({
      fill: 'black',
      pointerDirection: 'down',
      pointerWidth: 10,
      pointerHeight: 10,
      lineJoin: 'round',
      shadowColor: 'black',
      shadowBlur: 10,
      shadowOffset: 10,
      shadowOpacity: 0.5
    }));

    tooltip.add(new Konva.Text({
      text: 'Yoda has powers...',
      fontFamily: 'Calibri',
      fontSize: 18,
      padding: 5,
      fill: 'white'
    }));


    var image = new Image();
    image.onload = function() {
      var lion = new Konva.Image({
        image: image,
        x: 70,
        y: 75,
        draggable: true
      });
      layer.add(lion);
      // add the labels to layer
      layer.add(tooltip);
      layer.draw();
    };

    image.src = 'http://konvajs.github.io/assets/yoda.jpg';



    // add the layer to the stage
    stage.add(layer);
  </script>

</body>

</html>
Hitesh Kumar
  • 3,508
  • 7
  • 40
  • 71