如何在Famo.us中的表面之间滑动?

时间:2014-05-14 08:56:14

标签: javascript famo.us

使用以下Famo.us示例代码添加10个垂直显示的表面,宽度和高度均为100%,如何添加滑动功能,类似于滑动在iOS主屏幕上的工作方式?

define(function(require, exports, module) {
    var Engine           = require("famous/core/Engine");
    var Surface          = require("famous/core/Surface");
    var SequentialLayout = require("famous/views/SequentialLayout");

    var mainContext = Engine.createContext();

    var sequentialLayout = new SequentialLayout({
        direction: 0
    });
    var surfaces = [];

    sequentialLayout.sequenceFrom(surfaces);

    for (var i = 0; i < 10; i++) {
        surfaces.push(new Surface({
            content: "Surface: " + (i + 1),
            size: [window.innerWidth, window.innerHeight],
            properties: {
                backgroundColor: "hsl(" + (i * 360 / 10) + ", 100%, 50%)",
                lineHeight: window.innerHeight/10 + "px",
                textAlign: "center"
            }
        }));
    }

    mainContext.add(sequentialLayout);
});

2 个答案:

答案 0 :(得分:6)

您可以使用启用了分页的Scrollview类来实现iOS主屏幕的效果。这允许您实际从一个页面拖动到另一个页面或滑动。我相信EdgeSwapper类只会处理滑动。

以下是修改后使用Scrollview进行分页的示例。

希望这有帮助!

var Engine           = require("famous/core/Engine");
var Surface          = require("famous/core/Surface");
var Scrollview       = require("famous/views/Scrollview");

var mainContext = Engine.createContext();

var scrollview = new Scrollview({
    direction: 0,
    paginated: true
});
var surfaces = [];

scrollview.sequenceFrom(surfaces);

for (var i = 0; i < 10; i++) {
    surface = new Surface({
        content: "Surface: " + (i + 1),
        size: [window.innerWidth, window.innerHeight],
        properties: {
            backgroundColor: "hsl(" + (i * 360 / 10) + ", 100%, 50%)",
            lineHeight: window.innerHeight/10 + "px",
            textAlign: "center"
        }
    });

    surface.pipe(scrollview);

    surfaces.push(surface);
}

mainContext.add(scrollview);

答案 1 :(得分:0)

你有没有看过EdgeSwapper?我想这可能是你正在寻找的一个例子: https://github.com/Famous/examples/blob/master/src/examples/views/EdgeSwapper/example.js