0.7.8 • Published 3 years ago

spotlight.js v0.7.8

Weekly downloads
96
License
Apache-2.0
Repository
github
Last release
3 years ago

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

Get Latest Build (Stable):

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):

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>
<head>
    <script src="spotlight.bundle.js"></script>
    <title></title>
</head>
<body>
    <!-- CONTENT -->
</body>
</html>

2. Add the class _spotlight_ to an anchor element accordingly, e.g.:

<a class="spotlight" href="img1.jpg">
    <img src="thumb1.jpg">
</a>
<a class="spotlight" href="img2.jpg">
    <img src="thumb2.jpg">
</a>
<a class="spotlight" href="img3.jpg">
    <img src="thumb3.jpg">
</a>

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:

<div class="spotlight" data-src="img1.jpg">
    <div><!-- ... --></div>
</a>

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.:

<div class="spotlight-group">
    <a class="spotlight" href="dog1.jpg">
        <img src="dog1-thumb.jpg">
    </a>
    <a class="spotlight" href="dog2.jpg">
        <img src="dog2-thumb.jpg">
    </a>
    <a class="spotlight" href="dog3.jpg">
        <img src="dog3-thumb.jpg">
    </a>
</div>
<div class="spotlight-group">
    <a class="spotlight" href="cat1.jpg">
        <img src="cat1-thumb.jpg">
    </a>
    <a class="spotlight" href="cat2.jpg">
        <img src="cat2-thumb.jpg">
    </a>
    <a class="spotlight" href="cat3.jpg">
        <img src="cat3-thumb.jpg">
    </a>
</div>

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.: <a class="spotlight" data-preftech="false"></a>.

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).

Example:
<div class="spotlight-group" data-title="Untitled" data-animation="fade"
     data-fullscreen="false" data-maximize="false" data-minimize="false">
    <a class="spotlight" href="cat1.jpg" data-title="This is a title.">
        <img src="cat1-thumb.jpg">
    </a>
    <a class="spotlight" href="cat2.jpg" data-description="This is a description.">
        <img src="cat2-thumb.jpg">
    </a>
    <a class="spotlight" href="cat3.jpg">
        <img src="cat3-thumb.jpg" alt="This is a title.">
    </a>
</div>

Hint: The 2nd image gets the title "Untitled" from the group attributes.

Control elements could also whitelisted as a comma-separated list, e.g.:

<div class="spotlight-group" data-control="fullscreen,autofit,theme">

Use a whitelist to enable controls gets priority over other ambiguous options.

The same from above as explicitly:

<div class="spotlight-group" data-fullscreen="true" data-contrast="true"
     data-zoomin="false" data-zoomout="false" data-autofit="true">

When control attributes are not specified they are automatically enabled by default.

Therefore the example above could be shortened to:

<div class="spotlight-group" data-zoomin="false" data-zoomout="false">

Since "zoom" is a shorthand for both zoom buttons, this is the same:

<div class="spotlight-group" data-zoom="false">

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:

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:

Spotlight.show(gallery);

Show gallery with custom options:

Spotlight.show(gallery, {
    index: 2,
    theme: "white",
    autohide: false,
    control: ["autofit", "zoom"]
});

Close gallery:

Spotlight.close();

Next slide:

Spotlight.next();

Previous slide:

Spotlight.prev();

Goto slide:

Spotlight.goto(3);

Zoom to:

Spotlight.zoom(1.5);

Toggle theme:

Spotlight.theme();

Set theme:

Spotlight.theme("white");
Spotlight.theme("dark");

Toggle fullscreen:

Spotlight.fullscreen();

Set fullscreen:

Spotlight.fullscreen(true);
Spotlight.fullscreen(false);

Toggle autofit:

Spotlight.autofit();

Set autofit:

Spotlight.autofit(true);
Spotlight.autofit(false);

Toggle menu:

Spotlight.menu();

Set menu:

Spotlight.menu(true);
Spotlight.menu(false);

Example ES6:

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:

#spotlight {
    /* font styles, background */
}
#spotlight .title{
    /* image title */
}
#spotlight .description{
    /* image description */
}
#spotlight .page{
    /* current page */
}
#spotlight .fullscreen{
    /* button fullscreen */
}
#spotlight .autofit{
    /* button autofit */
}
#spotlight .zoom-out{
    /* button zoom out */
}
#spotlight .zoom-in{
    /* button zoom in */
}
#spotlight .theme{
    /* button theme */
}
#spotlight .player{
    /* button autoplay */
}
#spotlight .close{
    /* button close */
}
#spotlight .arrow-left{
    /* button arrow left */
}
#spotlight .arrow-right{
    /* button arrow right */
}

Themes

Customize builtin themes

Use the same classes as above:

#spotlight.white .title{
    /* image title in white theme */
}
#spotlight.dark{
    /* main background in dark theme */
}

Create New Themes

Define styles, e.g. for the custom theme name "my-theme":

#spotlight.my-theme .title{
    /* image title in custom theme */
}
#spotlight.my-theme{
    /* main background in custom theme */
}

Apply custom theme via markdown:

<a class="spotlight" href="img.jpg" data-theme="my-theme">
    <img src="thumb.jpg">
</a>

Or apply custom theme via API:

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:

#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:

#spotlight .scene img.my-animation{
    opacity: 0 !important;
    filter: grayscale(1);
}

Apply custom animation via markdown:

<a class="spotlight" href="img.jpg" data-animation="my-animation">
    <img src="thumb.jpg">
</a>

Or apply custom animation via API:

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>
<head>
    <title></title>
    <link rel="preload" href="spotlight.bundle.js" as="script">
</head>
<body>
    <!-- 
    CONTENT 
    -->
    <script src="spotlight.bundle.js" async></script>
</body>
</html>

Initialize library manually (once):

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:

npm run build

The destination folder of the build is: /dist/


Copyright 2019 Nextapps GmbH Released under the Apache 2.0 License

0.7.8

3 years ago

0.7.6

3 years ago

0.7.72

3 years ago

0.7.5

3 years ago

0.7.53

3 years ago

0.7.7

3 years ago

0.7.52

3 years ago

0.7.43

3 years ago

0.7.62

3 years ago

0.7.42

3 years ago

0.7.41

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.0

3 years ago

0.6.6

4 years ago

0.6.5

5 years ago

0.6.2

5 years ago

0.6.12

5 years ago

0.6.11

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

6 years ago