この例の 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);
});