• Stars
    star
    532
  • Rank 80,544 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The lightest lightbox ever made.

basicLightbox

Donate via PayPal

The lightest lightbox ever made.

Contents

Demos

Name Description Link
Default Includes most features. Try it on CodePen
DOM elements/nodes Use DOM elements/nodes in basicLightbox. Try it on CodePen
Create element Use .createElement() with basicLightbox. Try it on CodePen
Events Multiple ways to handle events. Try it on CodePen

Features

  • Works in all modern browsers and IE11 (with polyfills)
  • Supports images, videos, iframes and any kind of HTML
  • Creates a lightbox from a string or from a DOM element/node
  • Zero dependencies
  • CommonJS and AMD support
  • Simple JS API

Requirements

basicLightbox depends on the following browser features and APIs:

Some of these APIs are capable of being polyfilled in older browsers. Check the linked resources above to determine if you must polyfill to achieve your desired level of browser support.

Setup

We recommend installing basicLightbox using npm or yarn.

npm install basiclightbox
yarn add basiclightbox

Include the CSS file in the head tag and the JS file at the end of your body tag…

<link rel="stylesheet" href="dist/basicLightbox.min.css">
<script src="dist/basicLightbox.min.js"></script>

…or skip the JS file and use basicLightbox as a module:

const basicLightbox = require('basiclightbox')
import * as basicLightbox from 'basiclightbox'

API

.create(content, opts)

Creates a new basicLightbox instance.

Be sure to assign your instance to a variable. Using your instance, you can…

  • …show and hide the lightbox.
  • …check if the the lightbox is visible.
  • …modify the content of the lightbox.

Examples:

const instance = basicLightbox.create(`
	<h1>Dynamic Content</h1>
	<p>You can set the content of the lightbox with JS.</p>
`)
const instance = basicLightbox.create(`
	<h1>Not closable</h1>
	<p>It's not possible to close this lightbox with a click.</p>
`, {
	closable: false
})
const instance = basicLightbox.create(
	document.querySelector('#template')
)

Parameters:

  • content {Node|String} Content of the lightbox.
  • opts {?Object} An object of options.

Returns:

  • {Object} The created instance.

.visible()

Returns true when a lightbox is visible. Also returns true when a lightbox is currently in the process of showing/hiding and not fully visible/hidden, yet.

Example:

const visible = basicLightbox.visible()

Returns:

  • {Boolean} Visibility of any lightbox.

Instance API

Each basicLightbox instance has a handful of handy functions. Below are all of them along with a short description.

.show(cb)

Shows a lightbox instance.

Examples:

instance.show()
instance.show(() => console.log('lightbox now visible'))

Parameters:

  • cb(instance) {?Function} A function that gets executed as soon as the lightbox starts to fade in.

.close(cb)

Closes a lightbox instance.

Examples:

instance.close()
instance.close(() => console.log('lightbox not visible anymore'))

Parameters:

  • cb(instance) {?Function} A function that gets executed as soon as the lightbox has been faded out.

.visible()

Returns true when the lightbox instance is visible. Also returns true when the lightbox is currently in the process of showing/hiding and not fully visible/hidden, yet.

Example:

const visible = instance.visible()

Returns:

  • {Boolean} Visibility of lightbox.

.element()

Returns the DOM element/node associated with the instance.

Example:

const elem = instance.element()

Returns:

  • {Node} DOM element/node associated with the instance.

Options

The option object can include the following properties:

{
	/*
	 * Prevents the lightbox from closing when clicking its background.
	 */
	closable: true,
	/*
	 * One or more space separated classes to be added to the basicLightbox element.
	 */
	className: '',
	/*
	 * Function that gets executed before the lightbox will be shown.
	 * Returning false will prevent the lightbox from showing.
	 */
	onShow: (instance) => {},
	/*
	 * Function that gets executed before the lightbox closes.
	 * Returning false will prevent the lightbox from closing.
	 */
	onClose: (instance) => {}
}

Import src/styles/main.scss directly to customize the look of basicLightbox:

$basicLightbox__background: rgba(0, 0, 0, .8); // Background color
$basicLightbox__zIndex: 1000; // Stack order
$basicLightbox__duration: .4s; // Transition duration
$basicLightbox__timing: ease; // Transition timing

@import 'src/styles/main';

More Repositories

1

Lychee

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.
PHP
6,312
star
2

Ackee

Self-hosted, Node.js based analytics tool for those who care about privacy.
JavaScript
4,121
star
3

basicScroll

Standalone parallax scrolling for mobile and desktop with CSS variables.
JavaScript
3,633
star
4

formbase

Better default styles for common input elements.
SCSS
567
star
5

basicModal

Easy-to-use dialog system for modern web-apps.
JavaScript
283
star
6

ackee-tracker

Transfer data to Ackee.
JavaScript
190
star
7

basicContext

Easy-to-use context-menu for your website or webapp.
JavaScript
168
star
8

Rosid

Just-in-time development server and static site generator.
JavaScript
143
star
9

nice-try

Tries to execute a function and discards any error that occurs.
JavaScript
66
star
10

basicGrid

A Foundation-like grid system based on the flex display property.
SCSS
56
star
11

basicSlider

A slider in its purest form.
JavaScript
33
star
12

scrollSnap

Section-based scrolling for your site.
JavaScript
27
star
13

fsify

Convert an array of objects into a persistent or temporary directory structure.
JavaScript
26
star
14

Skeleton-Components

A front-end Malvid template build upon Rosid.
CSS
24
star
15

use-ackee

Use Ackee in React.
JavaScript
23
star
16

basicRotate

Rotate throw a set of 360 degree images using your mouse or finger.
JavaScript
20
star
17

ackee-bitbar

Ackee stats in your macOS menu bar.
JavaScript
16
star
18

ackee-lighthouse

Send Lighthouse reports to Ackee.
JavaScript
13
star
19

Skeleton-EJS

A front-end template build upon Rosid.
CSS
13
star
20

basicPlaceholder

Easy-to-use persistent placeholders for input fields.
JavaScript
10
star
21

basicNotification

Easy-to-use notification-system for your website or webapp.
CoffeeScript
9
star
22

basicPaginate

Paginate a NodeList like there's no tomorrow.
JavaScript
9
star
23

limit-number

Limit a number between a min and max value.
JavaScript
7
star
24

zbarimg

Scan photos using ZBar in Node.js.
CoffeeScript
6
star
25

dribbble-2x

Safari extension for Dribbble, which always shows the @2x version.
JavaScript
6
star
26

rosid-handler-sass

Load SCSS and transform to CSS, add vendor prefixes and minify.
JavaScript
6
star
27

basicTasks

A collection of gulp-tasks used in personal projects.
JavaScript
5
star
28

rosid-handler-twig

Load Twig templates and render them.
JavaScript
5
star
29

Feedboard

Design your feed.
JavaScript
5
star
30

Skeleton-NJK

A front-end template build upon Rosid.
CSS
5
star
31

key-value-replace

Replace key/value pairs in a string.
JavaScript
5
star
32

rosid-handler-ejs

Load EJS templates and render them.
JavaScript
5
star
33

lychee-watermark

Adds a second watermarked photo when uploading images to Lychee.
PHP
5
star
34

require-data

Extracts data out of multiple file types.
JavaScript
5
star
35

lychee-redirect

Redirect from an album-name to a Lychee-album.
PHP
5
star
36

rename-extension

Changes the the extension of a given filename or path.
JavaScript
5
star
37

rosid-handler-njk

Load Nunjucks templates and render them.
JavaScript
4
star
38

rosid-handler-js

Load, transform, bundle and compress JS.
JavaScript
4
star
39

basicFit

Turn elements on your site into a responsive unified grid.
CoffeeScript
4
star
40

rosid-handler-node

Load JS and transform to HTML.
JavaScript
3
star
41

count-between

Counts up and down between two numbers.
JavaScript
3
star
42

ausgabe

Tiny logger with zero defaults.
JavaScript
3
star
43

modulizer

Wrap this snippets around your code to support CommonJS, AMD and non-module-definitions.
JavaScript
3
star
44

eslint-config

ESLint configuration for my personal projects.
JavaScript
2
star
45

pdfconcat

Concat multiple pdfs using pdfunite in Node.js.
CoffeeScript
2
star
46

continuous-stealthy-require

Requires a fresh, uncached module without causing a memory leak.
JavaScript
2
star
47

ackee-faker

Fills Ackee with fake data.
JavaScript
2
star
48

Ackee-Netlify-Test-Instance

JavaScript
1
star
49

rosid-handler-js-next

Load, transform, bundle and compress modern JS.
JavaScript
1
star
50

Skeleton-React

A front-end template build upon Rosid.
JavaScript
1
star
51

vh-variable

TypeScript
1
star