Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/konva@4.1.0/konva.min.js"></script>
    <meta charset="utf-8" />
    <title>Konva Animate Position Demo</title>
    <style>
      body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #f0f0f0;
      }
    </style>
  </head>
  <body>
    <button type="submit" onclick="animate()">Animate</button>
    <div id="container"></div>
    <script>
      var width = window.innerWidth;
      var height = window.innerHeight;
      var stage = new Konva.Stage({
        container: 'container',
        width: width,
        height: height,
        draggable: true,
      });
      var layer = new Konva.Layer();
      var hexagon = new Konva.RegularPolygon({
        x: stage.width() / 2,
        y: stage.height() / 2,
        sides: 6,
        radius: 20,
        fill: 'red',
        stroke: 'black',
        strokeWidth: 4
      });
      layer.add(hexagon);
      stage.add(layer);
      
      layer.draw();
      var velocity = 500;
      var anim = new Konva.Animation(function(frame){
        var dist = velocity * (frame.timeDiff / 1000);
        if (stage.x() > stage.width() * 0.75) {
          anim.stop();
          stage.to({x: dist});
        }
        stage.move({x: dist, y: 0});
      }, layer);
      anim.start();
    </script>
  </body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kalyanampro
0viewers