Add the script tag to the <head>
of your page
<script src="https://cdn.unicorn.studio/v1.2.0/unicornStudio.umd.js"></script>
or import into your component
import * as UnicornStudio from './path/to/unicornStudio.umd.js'
Any element with data-us-project
will get initialized by calling UnicornStudio.init()
. If you're hosting your own exported JSON file, use data-us-project-src
to point to its location. If you host your own JSON, remembder you'll need to update this file when you make changes to your scene in Unicorn.studio.
<div class="unicorn-embed"
data-us-project="YOUR_PROJECT_EMBED_ID"
data-us-project-src="path/to/your/PROJECT_ID.json"
data-us-scale="1"
data-us-dpi="1.5"
data-us-disableMobile="true"
></div>
<script>
UnicornStudio.init().then(scenes => {
// Scenes are ready
}).catch((err) => {
console.error(err);
});
</script>
You can add a scene dynamically during or after pageload.
<div class="unicorn-embed" id="unicorn"></div>
<script>
UnicornStudio.addScene({
elementId: 'unicorn', // id of the HTML element to render your scene in (the scene will use its dimensions)
fps: 60, // frames per second (0-120) [optional]
scale: 1, // rendering scale, use smaller values for performance boost (0.25-1) [optional]
dpi: 1, // pixel ratio [optional]
projectId: 'YOUR_PROJECT_EMBED_ID', // the id string for your embed (get this from "embed" export)
filePath: 'path/to/your/PROJECT_ID.json', // if youre hosting your own exported json code, point to it here
interactivity: { // [optional]
mouse: {
disableMobile: true, // disable touch movement on mobile
momentum: 1.1 // mouse movement momentum
},
scroll: {
disableMobile: true, // disable scroll effects on mobile
momentum: 1.1 // scroll momentum
}
}
}).then(scene => {
// Scene is ready
// To remove a scene, you can use:
// scene.destroy()
}).catch((err) => {
console.error(err);
});
</script>
Any values set in the UI will be overridden by values defined in the optional params.
UnicornStudio.destroy();