Next (Commands) Previous (Data API)

Basic JavaScript API

If jQuery is not loaded, you can still interact with the clara api through plain javascript. The DOM element must be passed in to all commands as the ‘el‘ attribute.

This still requires that you specify the Lightning JS code snippet in your web page tough.

init is used to initialize the player. The player must be initialized before sending any further commands.

  • el (DOM Element): The DOM element to attach the player to. required
  • id (String): The id of the scene. required
var element = document.getElementById('my-clara-scene');
clara('init', {el: element, id: 'uuid', loadingImg: '/img/splash.jpg'});

The clara function returns a Javascript promise that allows you to execute a function after the scene is loaded.

clara('init', {el: element, id: 'uuid', loadingImg: '/img/splash.jpg'}).then(function() {
    alert('player started');
});

You can also run the commands:

clara('fullscreen', {el: element});
clara('script', {el: element, fn: function(ctx) {}});
clara('assignMaterial', {el: element, material: 'RedFabric', assignTo: 'ChairMesh'});

Next (Commands) Previous (Data API)