Git Product home page Git Product logo

Comments (1)

heitorlisboa avatar heitorlisboa commented on June 9, 2024 1

The problem is that you're setting the pointer events as auto in the .transparent_content container. If any element that's over the canvas can catch the pointer events, the canvas will not be able to catch those events, therefore you'll not be able to drag the rect.

Here's the code for anyone who wants to check it without needing to download the .txt:
<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/[email protected]/konva.min.js"></script>
    <meta charset="utf-8" />
    <title>Konva Rect Demo</title>
    <style>
      body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #f0f0f0;
      }
      #container {
        position: absolute;
        width: 500px;
        height: 500px;
        margin-top: 100px;
      }

      .transparent_container {
        position: absolute;
        height: 600px;
        width: 600px;
        z-index: 3;
        pointer-events: none;
        overflow: auto;
        background-color: transparent;
      }

      .transparent_container .transparent_content {
        height: 100000px;
        background-color: transparent;
        width: 100%;
        overflow: auto;
        pointer-events: auto;
      }
    </style>
  </head>
  <body>
    <div id="container"></div>

    <div class="transparent_container">
      <div class="transparent_content"></div>
    </div>
    <script>
      var width = window.innerWidth;
      var height = window.innerHeight;

      var stage = new Konva.Stage({
        container: "container",
        width: width,
        height: height,
      });

      var layer = new Konva.Layer();

      var rect1 = new Konva.Rect({
        x: 20,
        y: 20,
        width: 100,
        height: 50,
        fill: "green",
        stroke: "black",
        strokeWidth: 4,
        draggable: true,
      });
      // add the shape to the layer
      layer.add(rect1);

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

from konva.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.