Famo.us如何从下到上(或从右到左)填充滚动视图?

时间:2014-06-22 13:29:13

标签: famo.us

假设我有方向1(垂直)的滚动视图。在填充scrollView时,项目会显示并从上到下对齐。

我想知道是否有办法扭转这种顺序,即使scrollView从底部到顶部填充。一个很好的使用示例是消息列表。您希望最后一条消息始终显示在列表的底部。默认情况下,消息将在顶部对齐,这不方便。

enter image description here

[编辑] 我刚刚发现我们可以根据覆盖outputFrom函数回调的偏移量轻松设置我们自己的变换。例如,以下内容将反转滚动内容:

scrollview.outputFrom(function(offset)
{
       return  Transform.translate(0, -offset)
});

3 个答案:

答案 0 :(得分:0)

正如famo.us documentation所说:“Scrollview将按指定的方向顺序排列一系列可渲染物”,因此它会按照您提供的顺序对表面进行排序。

我的建议是将曲面添加到列表中,然后反过来将它们添加到ScrollView中。

答案 1 :(得分:0)

您正在寻找的是非移位()。您可以在codefamo.us

查看以下代码
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var StateModifier = require('famous/modifiers/StateModifier');
var Transform = require('famous/core/Transform');
var Easing = require('famous/transitions/Easing');
var Scrollview = require('famous/views/Scrollview');

var mainContext = Engine.createContext();
var items = [];
var scroll = new Scrollview();
mainContext.add(scroll);
var counter=0;
scroll.sequenceFrom(items);

function addOne() {
    setTimeout(function() {
        var surface = new Surface({
            size: [100, 100],
            content: 'surf: '+counter++,
            properties: {
                textAlign: 'center',
                lineHeight: '20px'
            }
        });
        items.unshift(surface);

        if (counter<10) 
        addOne();
    },2000);
}
addOne();

答案 2 :(得分:0)

它是否像你建议的那样,在全部旋转180˚时工作得很好。示例:http://jsfiddle.net/tamtamchik/LA49a/3/

Famous.loaded(function () {
    var Engine = Famous.Core.Engine;
    var Surface = Famous.Core.Surface;
    var Scrollview = Famous.Views.Scrollview;
    var Timer = Famous.Utilities.Timer;
    var Transform = Famous.Core.Transform;
    var StateModifier = Famous.Modifiers.StateModifier;
    var ContainerSurface = Famous.Surfaces.ContainerSurface;

    var mainContext = Engine.createContext();

    var scrollview = new Scrollview();
    var surfaces = [];
    var i = 0;
    var surfaceHeight = 50;

    scrollview.sequenceFrom(surfaces);

    Timer.setInterval(function () {
        var container = new ContainerSurface({
            size: [undefined, surfaceHeight]
        });

        var temp = new Surface({
            content: "Surface: " + (i + 1),
            size: [undefined, surfaceHeight],
            properties: {
                backgroundColor: "hsl(" + (i * 360 / 40) + ", 100%, 50%)",
                lineHeight: "50px",
                textAlign: "center"
            }
        });

        var surfaceRotate = new StateModifier({
            transform: Transform.rotateZ(Math.PI)
        });

        var surfacePush = new StateModifier({
            transform: Transform.translate(window.innerWidth, surfaceHeight)
        });

        container.add(surfacePush).add(surfaceRotate).add(temp);
        container.pipe(scrollview);
        temp.pipe(scrollview);
        surfaces.unshift(container);
        i++;
    }, 400);

    var rotate = new StateModifier({
        transform: Transform.rotateZ(Math.PI)
    });

    var push = new StateModifier({
        transform: Transform.translate(window.innerWidth, window.innerHeight)
    });

    mainContext.add(push).add(rotate).add(scrollview);
});