Usage

This guide contains Javascript usage, see Markup Guide and Themes for Html and CSS usage.

In html file there are two nested div elements with class name .rs-container and .rs-sg3d which serve as the base container.

1
2
3
4
5
 <div class="rs-container">
   <div class="rs-sg3d">
   ...
   </div>
 </div>
Copy to clipboard

To bootstrap the app in javascript, query .rs-sg3d element and pass it as an input argument to SphericalGallery constructor:

1
2
 var el = document.querySelector('.rs-sg3d');
 var sg3d = new SphericalGallery(el);
Copy to clipboard

A second object argument filled with configuration options can be passed to the constructor:

1
2
3
4
5
6
7
8
9
 var sg3d = new SphericalGallery(el, {
   containerZ:-2500,
   boxThickness:20,
   control:'mousemove',
   backImage:'assets/back.png',
   categoryMenu:{
     horizontal:true
   }
 });
Copy to clipboard

API Methods

  • target(index)

    Target an item, bring it to center front and show its title and description. index: The item index

  • next

    Target the next item in current category

  • prev

    Target the previous item in current category

Dispatched Events

  • cload

    Fire when a category is beginning to load

  • cloadcomplete

    Fire when a category is finished loading

  • target

    Fire when an item is being targeted

Examples

Assign sg3d to window context then call its API methods:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 window.sg3d = sg3d;

 // Target item with id: 1
 sg3d.target(1);
 // ...

 // Target next item
 sg3d.next();
 // ...

 // Target previous item
 sg3d.prev();
Copy to clipboard

Add event listeners:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 // Trigger every time an item is targeted
 sg3d.addEventListener('target', function(e) {
   console.log(e.detail);
 });

 // Trigger when a category begins to load
 sg3d.addEventListener('cload', function(e) {
   console.log(e.detail);
 });

 // Trigger when a category finished loading
 sg3d.addEventListener('cloadcomplete', function(e) {
   console.log(e.detail);
 });
Copy to clipboard