npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

basiclightbox

v5.0.4

Published

The lightest lightbox ever made

Downloads

33,366

Readme

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';