HTML5画布选择的类型或类名称kineticjs形状

选择类型或类名称kineticjs形状,我们可以使用的类型或类名称get()方法;该方法返回的get()选择器字符串匹配节点数组。返回的数组是一个动力学。收藏阵列,这基本上是一个特殊的each()方法典型的JavaScript数组。该each()方法使我们能够迅速遍历数组中的每个节点。


<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
      #buttons {
        position: absolute;
        top: 5px;
        left: 10px;
      }
      #buttons > input {
        padding: 10px;
        display: block;
        margin-top: 5px;
      }
    </style>
  </head>
  <body>
    <div id="container"></div>
    <div id="buttons">
      <input type="button" id="activate" value="Activate rectangles">
    </div>
    <script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.6.0.min.js"></script>
    <script defer="defer">
      var stage = new Kinetic.Stage({
        container: 'container',
        width: 578,
        height: 200
      });
      var layer = new Kinetic.Layer();

      for(var n = 0; n < 10; n++) {
        var circle = new Kinetic.Circle({
          x: Math.random() * stage.getWidth(),
          y: Math.random() * stage.getHeight(),
          radius: Math.random() * 50 + 25,
          fill: 'red',
          strokeWidth: 3
        });

        layer.add(circle);
      }

      var rect1 = new Kinetic.Rect({
        x: 250,
        y: 90,
        width: 100,
        height: 50,
        fill: 'green',
        strokeWidth: 3,
        offset: {
          x: 50,
          y: 25
        },
        draggable: true,
        name: 'rectangle'
      });

      var rect2 = new Kinetic.Rect({
        x: 400,
        y: 90,
        width: 100,
        height: 50,
        fill: 'green',
        strokeWidth: 3,
        offset: {
          x: 50,
          y: 25
        },
        draggable: true
      });

      layer.add(rect1);
      layer.add(rect2);
      stage.add(layer);

      document.getElementById('activate').addEventListener('click', function() {
        // select shapes by type
        var shapes = stage.get('Rect');

        // apply transition to all nodes in the array
        shapes.each(function(shape) {
          new Kinetic.Tween({
            node: shape, 
            duration: 1,
            scaleX: Math.random() * 2,
            scaleY: Math.random() * 2,
            easing: Kinetic.Easings.ElasticEaseOut
          }).play();
        });
      }, false);
    </script>
  </body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值