Spotlight.js

Web's most easy to integrate lightbox gallery library. Super-lightweight, outstanding performance, no dependencies.

Demo  •  Getting Started  •  Gallery Groups  •  Options  •  Styling  •  API  •  Custom Builds Spotlight runs out of the box: - No additional Javascript coding - No additional HTML snippets - No additional CSS resources - No additional icons/assets - No additional handling of dynamic content and event listener Show Demo Alternatively you can: 1. use the non-bundled version of this library (classically contains css files, image files, js files) 2. use the source files (compatible for the ES6 module system) ## Features - Gallery groups (group images to specific galleries) - Gallery Tools: - Fullscreen - Zoom in/out - Toggle resize - Switch theme - Autoplay - Progress Bar - Page - Title (inherits from image "alt"-attribute) - Description - Preloader - Prefetch next image (background task) - Custom options - Simply customize via markup (data-attributes) - Arrange built-in animations - Custom themes - Custom animations - Controls: - Keyboard - Touch - Mousemove - Mousewheel - Browser history detection - Back-Button (Android) - Global API for programmatic usage __Technical properties:__ - Outstanding performance - Memory optimized, tiny footprint, fully cleans up - Event capturing (just one single global event listener) - Bind event listener for components dynamically: - install when gallery opens - fully cleanup when gallery was closed - No dependencies, no jQuery - Responsive - Super-lightweight, all in all just 7kb gzip (js + css + html + icons) - Support for ES6 module system ## Getting Started __Version Explanation__
Bundle Standalone All assets bundled into one single file (js + css + html + icons).
Bundle CDN Also a bundled file (js + html), but icons and css will load from extern CDN.
Non-Bundled Each asset file exists separately. Recommended when extended customization is needed.
__Get Latest Build (Stable):__
Bundle Standalone:
spotlight.bundle.js Download https://rawcdn.githack.com/nextapps-de/spotlight/0.6.3/dist/spotlight.bundle.js

Bundle CDN:
spotlight.cdn.js Download https://rawcdn.githack.com/nextapps-de/spotlight/0.6.3/dist/spotlight.cdn.js

Non-Bundled:
spotlight.min.js Download https://rawcdn.githack.com/nextapps-de/spotlight/0.6.3/dist/js/spotlight.min.js
spotlight.css Download https://rawcdn.githack.com/nextapps-de/spotlight/0.6.3/dist/css/spotlight.css
img.zip Download Alternatively when using non-bundled version you can download icons from /dist/img/.

ES6 Modules:
src.zip Download The folder "src" of this Github repository.
__Get Latest Build (Nightly):__ Just exchange the version number from the URLs above with "master", e.g.: "/spotlight/0.6.3/dist/" into "/spotlight/__master__/dist". __Get Latest (NPM):__ ```cmd npm install spotlight.js ``` __Get Latest (ES6 Modules):__ https://github.com/nextapps-de/spotlight/tree/master/src ### Basic Setup __1. Just insert the script resource tag right after the documents head:__ > When you need to add custom styling through css class modifications it is recommended to load the library before you load the css which contains the modifications. Otherwise you have to add an _"!important"_ flag to override existing styles. ```html ``` __2. Add the class ___spotlight___ to an anchor element accordingly, e.g.:__ ```html ``` This also works with dynamically loaded content. There is no need to inject listeners on new elements. Instead Spotlight make use of global event capturing. Alternatively you can also use the Spotlight API for programmatically use. __Usage with non-anchor elements:__ ```html
``` Pretty much the same like anchors but use ___data-src___ instead of ___href___. ## Gallery-Groups Give one of the outer wrapping element the class ___spotlight-group___, e.g.: ```html
``` ## Options Pass options as declarative via data-attributes in the HTML markup or use the Spotlight API. > When using markup follow these style: `data-option="value"` (change _option_ and _value_ accordingly), e.g.: ``. You can either apply the following data-attributes to the ___spotlight-group___ wrapper element or apply them separately to each ___spotlight___ anchor element (that also overrides group definitions).
Option         Values Description
index number Sets the starting index when showing the gallery by using the Spotlight API. The index starts from 1.
onchange function(index) Pass a callback function which is get fired every time when a page has changed (the first parameter is equal to the new index).
Note: The image may not have been fully loaded when the event is fired (preloading phase). The index starts from 1.
animation "fade"
"slide"
"scale"
"flip"
Change animation (use built-ins)

Note: Could also combined as comma-separated list, e.g: data-animation="slide,fade,scale" (this is the default animation).
control string Show/hide control elements as "whitelisted" through a comma-separated list, e.g. data-control="autofit,page,fullscreen"
autohide true / false / number Enable/disable automatically hide controls when inactive, also set cooldown time
fullscreen true / false Show/hide fullscreen button
zoom true / false Show/hide both zoom buttons
zoomin true / false Show/hide zoom-in button
zoomout true / false Show/hide zoom-out button
autofit true / false Show/hide autofit button
theme true / false Show/hide theme button
player true / false / number Show/hide player button, also set delay between each tick
progress true / false Show/hide autoplay progress bar
infinite true / false Restart from beginning when no slides left
theme "white"
"dark"
Change the default theme
page true / false Show/hide page
title string / false Set image title or hide it

Note: When using image elements, this attribute will also inherit automatically from <img alt="...">. To prevent this behavior you can set data-title="false". This will hide the title regardless of any image alt-attributes.
description string / false Set image description or hide it
preloader true / false Enable/disable preloading of the current image (also hides spinner)
prefetch true / false Enable/disable preloading of the next image
##### Example: ```html
This is a title.
``` __Hint:__ The 2nd image gets the title "Untitled" from the group attributes. Control elements could also __whitelisted__ as a comma-separated list, e.g.: ```html
``` > Use a whitelist to enable controls gets priority over other ambiguous options. The same from above as __explicitly__: ```html
``` > When control attributes are not specified they are automatically enabled by default. Therefore the example above could be shortened to: ```html
``` Since "zoom" is a shorthand for both zoom buttons, this is the same: ```html
``` ## Spotlight API Also you can programmatically use Spotlight via the library API. This way does not require any dependant HTML elements (e.g. the classname "spotlight"). Define a gallery group as follows: ```js var gallery = [{ title: "Image 1", description: "This is a description.", src: "gallery/london-1758181.jpg" },{ title: "Image 2", description: "This is a description.", src: "gallery/sea-1975403.jpg" },{ title: "Image 3", description: "This is a description.", src: "gallery/newport-beach-2089906.jpg" }]; ``` Show gallery with default options: ```js Spotlight.show(gallery); ``` Show gallery with custom options: ```js Spotlight.show(gallery, { index: 2, theme: "white", autohide: false, control: ["autofit", "zoom"] }); ``` Close gallery: ```js Spotlight.close(); ``` Next slide: ```js Spotlight.next(); ``` Previous slide: ```js Spotlight.prev(); ``` Goto slide: ```js Spotlight.goto(3); ``` Zoom to: ```js Spotlight.zoom(1.5); ``` Toggle theme: ```js Spotlight.theme(); ``` Set theme: ```js Spotlight.theme("white"); ``` ```js Spotlight.theme("dark"); ``` Toggle fullscreen: ```js Spotlight.fullscreen(); ``` Set fullscreen: ```js Spotlight.fullscreen(true); ``` ```js Spotlight.fullscreen(false); ``` Toggle autofit: ```js Spotlight.autofit(); ``` Set autofit: ```js Spotlight.autofit(true); ``` ```js Spotlight.autofit(false); ``` Toggle menu: ```js Spotlight.menu(); ``` Set menu: ```js Spotlight.menu(true); ``` ```js Spotlight.menu(false); ``` __Example ES6:__ ```js import Spotlight from "./spotlight.js"; Spotlight.show( [ /* Gallery */ ], { /* Options */ } ); ``` > __Note:__ You may need to perform `npm run build` initially to make pre-compiled files available. ## Custom Styling To add custom styling just override CSS classes accordingly: ```css #spotlight { /* font styles, background */ } ``` ```css #spotlight .title{ /* image title */ } ``` ```css #spotlight .description{ /* image description */ } ``` ```css #spotlight .page{ /* current page */ } ``` ```css #spotlight .fullscreen{ /* button fullscreen */ } ``` ```css #spotlight .autofit{ /* button autofit */ } ``` ```css #spotlight .zoom-out{ /* button zoom out */ } ``` ```css #spotlight .zoom-in{ /* button zoom in */ } ``` ```css #spotlight .theme{ /* button theme */ } ``` ```css #spotlight .player{ /* button autoplay */ } ``` ```css #spotlight .close{ /* button close */ } ``` ```css #spotlight .arrow-left{ /* button arrow left */ } ``` ```css #spotlight .arrow-right{ /* button arrow right */ } ``` ## Themes __Customize builtin themes__ Use the same classes as above: ```css #spotlight.white .title{ /* image title in white theme */ } ``` ```css #spotlight.dark{ /* main background in dark theme */ } ``` __Create New Themes__ Define styles, e.g. for the custom theme name "my-theme": ```css #spotlight.my-theme .title{ /* image title in custom theme */ } #spotlight.my-theme{ /* main background in custom theme */ } ``` Apply custom theme via markdown: ```html ``` Or apply custom theme via API: ```js Spotlight.show([ /* Gallery */ ],{ theme: "my-theme" }); ``` ## Custom Animations > When you pass a custom animation, all other ambiguous animation settings will be overridden (also when mixed with built-ins). > The style class for a custom animation describes the __hidden state__ of an image. You can define your own custom animation by: 1. Extending the default styles (when image is shown) and corresponding transitions as follows: ```css #spotlight .scene img{ filter: grayscale(0); transition: filter 1s ease-out, opacity 0.5s ease-out; } ``` 2. Providing styles for the __hidden state__ of the transition by adding a custom animation name as a class: ```css #spotlight .scene img.my-animation{ opacity: 0 !important; filter: grayscale(1); } ``` Apply custom animation via markdown: ```html ``` Or apply custom animation via API: ```js Spotlight.show([ /* Gallery */ ],{ animation: "my-animation" }); ``` ## Preload Library / Async Load > If you like to override css classes for custom styling you may need to add ___!important___ flag to the css property value. ```html ``` Initialize library manually (once): ```js Spotlight.init(); ``` When using Spotlight exclusively through the API it is recommended to follow this practice. But there are some important facts you might need to know: 1. When loading the library before loading other stylesheets (which modifies the Spotlight default theme) you do not have to add a "!important" flag to the styles. 2. When using Spotlight with anchors it is recommended to load the library in the head section of the document to prevent executing the default anchor behavior when the user has clicked during page load. 3. In rare situations it also might produce a short flashing/reflow after page load, depending on your stack. Moving the script tag into the head section will solve this issue. ## Custom Builds > __Note:__ You can modify all source files e.g. stylesheets, template and also the icon files located in _/src/img/_. Providing a more handy way to pass custom icons is coming soon. Perform a full build: ```bash npm run build ``` The destination folder of the build is: _/dist/_ --- Copyright 2019 Nextapps GmbH
Released under the Apache 2.0 License