1

この例の jsfiddleでは、2 つのボックスの水平方向と垂直方向のドラッグを制限するために、 kineticjsに dragBoundsFunc を尊重させることができません。以下のコードを機能させるにはどうすればよいですか?

$(function() {
    var stage = new Kinetic.Stage({
        container: 'container',
        width: $("#container").width(),
        height: window.innerHeight * 0.9,
        listening: true
    });

    var scrollAreas = new Kinetic.Group();
    var scrollBars = new Kinetic.Group();
    var scrollBarsLayer = new Kinetic.Layer();

    var hscrollArea = new Kinetic.Rect({
        x: 10,
        y: stage.getHeight() - 30,
        width: stage.getWidth() - 40,
        height: 20,
        fill: "gray",
        opacity: 0.3
    });

    var hscroll = new Kinetic.Rect({
        x: 10,
        y: stage.getHeight() - 30,
        width: 130,
        height: 20,
        fill: "orange",
        draggable: true,
          dragBoundsFunc: function(pos) {
            return {
                x: pos.x,
                y: this.getAbsolutePostion().y
            };
          },
        opacity: 0.9,
        stroke: "black",
        strokeWidth: 1
    });

    var vscrollArea = new Kinetic.Rect({
        x: stage.getWidth() - 30,
        y: 10,
        width: 20,
        height: stage.getHeight() - 40,
        fill: "gray",
        opacity: 0.3
    });

    var vscroll = new Kinetic.Rect({
        x: stage.getWidth() - 30,
        y: 10,
        width: 20,
        height: 70,
        fill: "orange",
        draggable: true,
        dragBoundsFunc: function(pos) {
            return {
                x: this.getAbsolutePosition().x,
                y: pos.y
            };
        },
        opacity: 0.9,
        stroke: "black",
        strokeWidth: 1
    });

    scrollBars.on("mouseover", function() {
        document.body.style.cursor = "pointer";
    });
    scrollBars.on("mouseout", function() {
        document.body.style.cursor = "default";
    });

    scrollAreas.add(hscrollArea);
    scrollAreas.add(vscrollArea);
    scrollBars.add(hscroll);
    scrollBars.add(vscroll);

    scrollBarsLayer.add(scrollAreas);
    scrollBarsLayer.add(scrollBars);
    stage.add(scrollBarsLayer);
});
4

1 に答える 1

1

ですdragBoundFunc( ではなくdragBoundsFunc、 に注意してくださいs)。

于 2012-11-29T09:58:25.927 に答える