HTML5 Kinetic.js:Draggable仅限于画布大小

时间:2014-05-05 00:25:20

标签: javascript html5 html5-canvas kineticjs

我读了可拖动的边界,并且想要设置与画布相同的大小(因为图像在边缘处离开了网站,这可能吗?

1 个答案:

答案 0 :(得分:2)

var image = new Kinetic.Image({
    image : img,
    draggable: true,
  x : 100,
  y : 100,
  dragBoundFunc : function(pos) {
    if (pos.x < 0) {
      pos.x =0;
    }
    if (pos.y < 0) {
      pos.y =0;
    }
    if (pos.x > stage.width() - image.width()) {
      pos.x = stage.width() - image.width();
    }
    if (pos.y > stage.height() - image.height()) {
      pos.y = stage.height() - image.height();
    }
    return pos;
  }
});

DEMO