是否有方法在现有的DOM结构中创建famo.us容器?
我的意思是创建一个famo.us上下文,并将其附加到现有的元素中。
发布于 2014-12-08 23:12:36
绝对一点儿没错。这个被问了很多次。As shown in this video by Mike O'Brien at Famo.us这件事很容易做。
Example code on jsBin.
var el = document.getElementById('famous-app');
var mainContext = Engine.createContext(el);
var surface = new Surface({
size: [200, 200],
content: "Hello World, I'm Famo.us",
classes: ["red-bg"],
properties: {
lineHeight: "200px",
textAlign: "center",
backgroundColor: 'rgba(0,0,0,0.5)'
}
});
mainContext.add(surface);在本例中,DOM有一个带有id='famous-app'的元素。它可以是DOM中的任何元素。
<body>
<div>Not Famous here</div>
<div id="famous-app"></div>
</body>把它附加到DOM中。
Example 2 code on jsBin.
var el = document.createElement('div');
el.id = 'test';
document.body.appendChild(el);
var mainContext = Engine.createContext(el);
var surface = new Surface({
size: [200, 200],
content: "Hello World,<br/> Famo.us-ly added",
classes: ["red-bg"],
properties: {
lineHeight: "40px",
textAlign: "center",
backgroundColor: 'rgba(255,0,0,0.5)'
}
});
mainContext.add(surface); <body>
<div>Not Famous here</div>
</body>https://stackoverflow.com/questions/27365970
复制相似问题