标签:style io ar color os sp java for strong
Listening on Engine events is a catch-all but in most applications, you‘ll want to capture the events at a lower level.
<pre name="code" class="javascript">var Engine = require('famous/core/Engine'); var Surface = require('famous/core/Surface'); var Transform = require('famous/core/Transform'); var mainContext = Engine.createContext(); var StateModifier = require('famous/modifiers/StateModifier'); var surface = new Surface({ size: [undefined, 100], content: 'click me', properties: { color: 'white', textAlign: 'center', backgroundColor: '#FA5C4F' } }); var surface1 = new Surface({ size: [undefined, 100], content: 'Context', properties: { color: 'white', textAlign: 'center', backgroundColor: '#FA5C4F' } }); var surface2 = new Surface({ size: [undefined, 100], content: 'Engine', properties: { color: 'white', textAlign: 'center', backgroundColor: '#FA5C4F' } }); mainContext.add(surface); var node=mainContext.add(new StateModifier({ transform: Transform.translate(0, 150, 0) })); node.add(surface1); node.add(new StateModifier({ transform: Transform.translate(0, 150, 0) })).add(surface2); surface.on('click', function() { surface.setProperties({ backgroundColor: '#878785' }); }); Engine.on('click', function() { surface2.setProperties({ backgroundColor: '#878785' }); }); mainContext.on('click', function() { surface1.setProperties({ backgroundColor: '#878785' }); });
engine也会产生事件,像prerender和postrender,但是如非必要,不要监听。另外比较重要的事件就是resize。
var eventHandler = new EventHandler();eventHandler 是一个事件的发送和接受器,属于“自嗨”。
surface.on('click', function() { eventHandler.emit('hello'); }); eventHandler.on('hello', function() { surface.setContent('heard hello'); });若有多个eventhandler,假设有eventHandlerA,eventHandlerB,eventHandlerB若想相应eventHandlerA发送的事件 eventHandlerB.subscribe(eventHandlerA);或eventHandlerA.pipe(eventHandlerB);
var Engine = require('famous/core/Engine'); var Surface = require('famous/core/Surface'); var View = require('famous/core/View'); var Transform = require('famous/core/Transform'); var StateModifier = require('famous/modifiers/StateModifier'); var mainContext = Engine.createContext(); var myView = new View(); mainContext.add(myView); var surface = new Surface({ size: [100, 100], content: 'click me', properties: { color: 'white', textAlign: 'center', backgroundColor: '#FA5C4F' } }); var surface1 = new Surface({ size: [, 100], content: '2', properties: { color: 'white', textAlign: 'center', backgroundColor: '#FA5C4F' } }); myView.on('hello',function(){ surface1.setContent('receive'); }); myView.add(surface); var node=mainContext.add(new StateModifier({ align:[0.5,0.5], origin:[0.5,0.5] // transform: Transform.translate(150, 100, 0) })); node.add(surface1); surface.pipe(myView); // alternatively, myView.subscribe(surface); // normally inside view module's code myView._eventInput.on('click', function() { surface.setContent('goemit'); myView._eventOutput.emit('hello'); });
标签:style io ar color os sp java for strong
原文地址:http://blog.csdn.net/tpxwantpxwan/article/details/41344733