按照Kinetic在API上的教程,我一直在尝试将滚动条放入我的KineticJS应用程序中。我有滚动条本身应该出现,但我不知道如何处理事件监听器实际上让舞台或每个图层移动,以便滚动条实际上移动视图。
var hscrollArea = new Kinetic.Rect({
x: 10,
y: $(window).height() - 30 - 80, // 80 to account for the fixed footer
width: $(window).width() - 40,
height: 20,
fill: "gray",
opacity: 0.3
});
var hscroll = new Kinetic.Rect({
x: 10,
y: $(window).height() - 30 - 80,// 80 to account for the fixed footer
width: 130,
height: 20,
fill: "orange",
draggable: true,
dragBoundFunc: function(pos) {
// TODO: Move stage or layers at this point
console.log("dragBoundFunc: " + this);
return {
x: pos.x,
y: this.getAbsolutePostion().y
};
},
opacity: 0.9,
stroke: "black",
strokeWidth: 1
});
var vscrollArea = new Kinetic.Rect({
x: $(window).width() - 30,
y: 10,
width: 20,
height: $(window).height() - 40 - 80,
fill: "gray",
opacity: 0.3
});
var vscroll = new Kinetic.Rect({
x: $(window).width() - 30,
y: 10,
width: 20,
height: 70,
fill: "orange",
draggable: true,
dragBoundFunc: function(pos) {
// TODO: Move stage or layers at this point
console.log("dragBoundFunc: " + this);
return {
x: this.getAbsolutePosition().x,
y: pos.y
};
},
opacity: 0.9,
stroke: "black",
strokeWidth: 1
});
任何帮助将不胜感激:) 谢谢, 贝基
答案 0 :(得分:0)
拖动滚动条(矩形)时,可以移动舞台或图层。即,
stage.move(50,50);
stage.draw();
stage.move(-50,-50);
stage.draw();
答案 1 :(得分:0)
我建议将您想要滚动的对象放到他们自己的组中并相应地定位组,而不是尝试定位图层或舞台。组的大小将是组内所有对象的(轴对齐)边界框。您可以使用组的大小并将其与舞台的大小进行比较,以获得宽度和高度的比率。这些比率将用于帮助计算水平和垂直滚动条的大小(条形被拖动以创建滚动效果)。该比率还将用于确定何时显示和隐藏滚动条区域。尺寸的差异将有助于确定如何在舞台内定位小组。