javascript - 用于滚动的 KineticJS 变换层

标签 javascript scroll kineticjs

我一直在尝试按照 Kinetic API 上的教程将滚动条放入我的 KineticJS 应用程序中。我让滚动条本身按其应有的方式显示,但我不确定如何使用事件监听器来实际移动舞台或每个层,以便滚动条实际移动 View 。

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
});

任何帮助将不胜感激:) 谢谢, 贝基

最佳答案

拖动滚动条(矩形)时,您可以移动舞台或图层。即,

stage.move(50,50);
stage.draw();

stage.move(-50,-50);
stage.draw();

关于javascript - 用于滚动的 KineticJS 变换层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133130/

相关文章:

jquery - 滚动库中下一个和上一个按钮的错误

Android:滚动 ImageView

javascript - 为什么 Safari 允许基于滚动的视频按预期工作,而其他浏览器则不允许?

html - KineticJS setText 方法像定时器一样更新

javascript - 如何避免在使用 v-for 的元素上使用 v-if

javascript - 谁能告诉我这个符号是什么

javascript - 在 AngularJS 中如何从一个 Controller 重定向到另一个 Controller ?

javascript - 无法读取 CKEditor ASP.NET 的 null 属性 'unselectable'

javascript - KineticJS 文本作为链接?

javascript - Kinetic.js - 图像不显示