Git Product home page Git Product logo

bs-lightbox's Introduction

@rat.md / bs-lightbox

bs-lightbox is a simple Lightbox system based on the Bootstrap-native Carousel and Modal components, compatible with Bootstrap 5 and Bootstrap 4.

Features

  • Compatible with Bootstrap v5 and Bootstrap v4
  • Native Lightbox environment using Bootstraps Carousel & Modal components
  • No stylesheet or CSS overwrites, just Bootstraps component & utility classes
  • Access to all Carousel & Modal options and events
  • Simple but useful API & Methods
  • Available as ES6 compiled JavaScript and as ES Module
  • Free/To/Use and written in Vanilla JS

Installation

You can download the latest release of the bs-lightbox package directly on the Release Page of the official GitHub repository, alternatively you can also receive your copy of this script using npm:

npm i @rat.md/bs-lightbox

Usage

bs-lightbox does not provide an own stylesheet, instead it just relies on the Bootstrap-native component and utility classes. Since bs-lightbox does not provide any bundled JS version, you've to make sure that Bootstrap's JavaScript library is loaded BEFORE the rat.lightbox file.

<html>
    <head>
        <!-- Include Bootstrap CSS -->
        <link href="path/to/your/css/bootstrap.min.css" />
    </head>
    <body>
        
        <!-- Simple Lightbox -->
        <img src="path/to/your/image.jpg" data-bs-handle="lightbox" />

        <!-- Include Bootstrap JS -->
        <script src="path/to/your/js/bootstrap.bundle.min.js"></script>

        <!-- Include @rat.md/bs-lightbox JS -->
        <script src="path/to/your/js/rat.lightbox.min.js"></script>

        <!-- Invoke Lightbox on all valid components -->
        <script>
            document.addEventListener('DOMContentLoaded', () => {
                rat.Lightbox.invoke();
            });
        </script>
    </body>
</html>

Usage as ES Module

bs-lightbox does also provide an ES-Module version, which can be found in the dist/esm folder. Depending on how you're including Bootstrap, you probably need to append the Carousel and Modal prototype objects / classes manually, as shown below.

import { Carousel, Modal } from 'bootstrap';                // Optional, depending on your usage
import { Lightbox } from '../esm/rat.lightbox.min.js';

// The following lines are only necessary, if the 'bootstrap' global is not added
Lightbox.CAROUSEL = Carousel;
Lightbox.MODAL = Modal; 

// Go on as usual, make sure the following line is execute when the DOM is ready.
Lightbox.invoke(
    null,       // Custom or Default selector
    {}          // Custom Configurations
);

Copyright & License

Written and Copyright by rat.md.

Published under der MIT license.

bs-lightbox's People

Contributors

sambrishes avatar

Watchers

 avatar

bs-lightbox's Issues

Version 1.2.0 - Roadmap

  • Improve Preloader script
    • Add loader: 'all' option to preload every image before the carousel is initialized (+ keep load / image option)
    • Fix white background effect when using the carousel with the loader option enabled
  • Add lightbox events
    • show.rat.lightbox, triggers before lightbox is created
    • shown.rat.lightbox, triggers after shown.bs.modal
    • hide.rat.lightbox, triggers before lightbox has been hidden
    • hidden.rat.lightbox, triggers after hidden.bs.modal
    • preload.rat.lightbox, triggers before pre-loading function
    • preloaded.rat.lightbox, triggers after all images has been pre-loaded
  • Filter same instances from .invoke() result
  • Add option to configure Modal, Carousel and Loader HTML snippets
  • Add option to configure class names for the used <img /> or <picture /> tag
  • Add possibility to include a <video> element when clicking on the lightbox element
  • Apply overflow:hidden to the modal body to keep border-radius (or find another solution)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.