Initialization and options
Sketchfab( version, iframe )
This constructor returns a new Sketchfab viewer instance bound to the given iframe element.
var iframe = document.getElementById( 'api-frame' );
var version = '1.12.1';
var client = new Sketchfab( version, iframe );
init( url, options )
This function initializes a viewer for the model with the given uid
.
The uid
is the identifier part in a model URL.
You can also pass an options object to this function. See below for available options.
var uid = '7w7pAfrCfjovwykkEeRFLGw5SXS';
client.init( uid, {
success: function onSuccess( api ){
api.start();
api.addEventListener( 'viewerready', function() {
//API is ready to use
console.log( 'Viewer is ready' );
} );
},
error: function onError() {
console.log( 'Viewer error' );
}
} );
Initialization options
You can pass callbacks and customization options when you initialize a viewer.
var uid = '7w7pAfrCfjovwykkEeRFLGw5SXS';
client.init( uid, {
success: function onSuccess( api ){ },
error: function onError() { },
camera: 0,
blending: 1,
autospin: 4,
annotation_cycle: 4,
transparent: 0
} );
-
success: function( api )
Required. This callback will be invoked when the viewer has been successfully initialized. It will be passed an
api
object so that you can interact with the viewer. -
error: function()
This callback will be invoked when the viewer can not be initialized.