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 <div class="rs-container">
2 <div class="rs-sg3d">
3 ...
4 </div>
5 </div>
To bootstrap the app in javascript, query .rs-sg3d element and pass it as an input argument to SphericalGallery constructor:
1 var el = document.querySelector('.rs-sg3d');
2 var sg3d = new SphericalGallery(el);
A second object argument filled with configuration options can be passed to the constructor:
1 var sg3d = new SphericalGallery(el, {
2 containerZ:-2500,
3 boxThickness:20,
4 control:'mousemove',
5 backImage:'assets/back.png',
6 categoryMenu:{
7 horizontal:true
8 }
9 });
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 window.sg3d = sg3d;
2
3 // Target item with id: 1
4 sg3d.target(1);
5 // ...
6
7 // Target next item
8 sg3d.next();
9 // ...
10
11 // Target previous item
12 sg3d.prev();
Add event listeners:
1 // Trigger every time an item is targeted
2 sg3d.addEventListener('target', function(e) {
3 console.log(e.detail);
4 });
5
6 // Trigger when a category begins to load
7 sg3d.addEventListener('cload', function(e) {
8 console.log(e.detail);
9 });
10
11 // Trigger when a category finished loading
12 sg3d.addEventListener('cloadcomplete', function(e) {
13 console.log(e.detail);
14 });