[英]Embedding famo.us in existing DOM
有没有办法在现有的DOM结构中创建一个famo.us容器?
我的意思是创建一个famo.us上下文,以及生成的.famous-container(?),并将其附加到现有元素。
绝对。 这问得很多。 正如Famo.us的Mike O'Brien在视频中所示,这很容易做到。
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>
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.