Nesting famo.us into an existing DOM
1 answer
Quite right. Many people ask about this. As shown in this video by Mike O'Brien on Famo.us , it's pretty easy to do.
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);
In this case, the DOM has an element with id='famous-app'
. It can be any element in your DOM.
<body>
<div>Not Famous here</div>
<div id="famous-app"></div>
</body>
To add it to the DOM.
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>
+5
source to share