如何在 famo.us 中使表面动态化

How to make a surface dynamic in famo.us?

本文关键字:表面 动态化 us famo      更新时间:2023-09-26

我想根据全局索引更改我著名的表面的文本内容,但文本没有递增。我该怎么做? 这是我的代码:

index = 0;是一个全局变量,根据表面上的单击次数递增

幻灯片.js

function _createBackground() {
    text = ['Hey', 'yo', '2']; 
    var background = new Surface({
        content: text[index],
        properties: {
            backgroundColor: '#FFFFF6',
            boxShadow: '0 10px 20px -5px rgba(0, 0, 0, 0.5)',
            cursor: 'pointer',         
        }
    });
    this.mainNode.add(background);
    background.on('click', function() {
        this._eventOutput.emit('click');
    }.bind(this));
}

幻灯片视图.js

var index = 0;
SlideshowView.prototype.showCurrentSlide = function() {
    this.ready = false;
    var slide = this.slides[this.currentIndex];
    console.log(this.currentIndex);
    index = this.currentIndex;
    this.lightbox.show(slide, function() {
        this.ready = true;
        slide.fadeIn();
    }.bind(this));
};

这是对调用例程的猜测,但您需要将索引范围限定到调用中。

function _createBackground(index) {
    text = ['Hey', 'yo', '2']; 
    var background = new Surface({
        content: text[index],
        properties: {
            backgroundColor: '#FFFFF6',
            boxShadow: '0 10px 20px -5px rgba(0, 0, 0, 0.5)',
            cursor: 'pointer',         
        }
    });
    this.mainNode.add(background);
    background.on('click', function() {
        this._eventOutput.emit('click');
    }.bind(this));
}

按原样进行后台调用

_createBackground.call(this, index);