kineticjs可拖动限制与dragBounds - 没有运行

时间:2013-04-07 16:38:36

标签: javascript canvas html5-canvas kineticjs

我想拖动我的舞台,限制顶部,左侧,右侧,底部使用dragBounds,但它不起作用

var stage = new Kinetic.Stage({
    container: 'container',
    width: 578,
    height: 363,
    draggable: true,
    dragBoundFunc: function(pos) {
        var newY = pos.y < 50 ? 50 : pos.y;
        return {
          x: pos.x,
          y: newY
        };
    },
    dragBounds: { // it's not running
        top: 10,
        bottom: 300,
        left: 0,
        right: 500   
    }
});

这是我的代码http://jsfiddle.net/kien16/aUWY2/

1 个答案:

答案 0 :(得分:4)

dragBounds不在当前版本的KineticJS中...使用dragBoundFunc

请在此处查看示例:Kineticjs dragBoundFunc for a rect in a rect

以下是kineticJS网站的教程:http://www.html5canvastutorials.com/kineticjs/html5-canvas-drag-and-drop-shapes-horizontally-or-vertically-tutorial/