VenoBox Documentation

repository·master·Indexed 20 days ago

https://github.com/nicolafranchini/venobox

VenoBox is a responsive JavaScript lightbox plugin for displaying images, inline content, iFrames, and videos in a modal window. Version 2.2.0 features touch-swipe gallery support, intelligent scaling for small devices, and a comprehensive API for programmatic control. It can be installed via npm or Composer and supports both vanilla JavaScript and jQuery environments.

Tokens
1.9K
Snippets
8
Records
9
Agent score
22%

What's inside VenoBox

  1. Set up VenoBox with Static HTML

    master

    If you are not using a package manager, download the latest release or use jsDelivr.

    1. Place the stylesheet in your <head>.
    2. Include the script near the end of your page, just before the closing </body> tag.
    <!-- In <head> -->
    <link rel="stylesheet" href="venobox/dist/venobox.min.css" />
    
    <!-- Before </body> -->
    <script src="venobox/dist/venobox.min.js"></script>
  2. Use VenoBox to create a lightbox

    master

    To use VenoBox, follow these two steps:

    1. HTML: Create links with a specific class (e.g., venobox) and set the href attribute to the large media file (image, video, etc.).
    2. JavaScript: Initialize the VenoBox class and provide a selector option that matches your HTML class.

    This plugin is suitable for images, inline contents, iFrames, and videos. It features a responsive design that preserves image height if the image is taller than the window to avoid microscopic resizing on small devices.

    <!-- 1. HTML Structure -->
    <a class="venobox" href="image01-big.jpg">
      <img src="image01-small.jpg" alt="image alt"/>
    </a>
    // 2. JavaScript Initialization
    import VenoBox from 'venobox';
    
    new VenoBox({
      selector: '.venobox'
    });
  3. Configure VenoBox CSS

    master

    VenoBox requires its stylesheet to be included in your project. You can import it directly into your CSS entry point or link it via an HTML <link> tag.

    Via CSS @import:

    @import "venobox/dist/venobox.min.css";

    Via HTML link:

    <link rel="stylesheet" href="node_modules/venobox/dist/venobox.min.css">
  4. Initialize VenoBox

    master

    To use VenoBox, instantiate the VenoBox constructor with an options object. By default, it searches for elements matching the .venobox selector and attaches click listeners to open them in a lightbox. You can also provide a custom selector or use the jQuery plugin bridge if jQuery is available in your environment.

    import VenoBox from './venobox.esm.js';
    
    // Initialize with default settings
    const vbox = new VenoBox();
    
    // Initialize with custom settings
    const vbox = new VenoBox({
      selector: '.my-custom-selector',
      autoplay: true
    });
  5. Configure VenoBox options

    master

    The VenoBox constructor accepts an options object to override default behaviors. Key configuration options include:

    OptionDefaultDescription
    selector'.venobox'CSS selector for the trigger elements.
    autoplayfalseWhether videos should autoplay.
    bgcolor'#fff'Background color of the content.
    border'0'Border thickness.
    customClassfalseA custom CSS class to add to the overlay.
    infinigallfalseWhether the gallery should loop infinitely.
    navigationtrueEnable/disable next/prev buttons.
    navKeyboardtrueEnable/disable keyboard navigation.
    navTouchtrueEnable/disable touch/swipe navigation.
    navSpeed300Transition speed in ms.
    numerationfalseShow '1 / 5' style numbering.
    overlayClosetrueAllow closing by clicking the overlay.
    overlayColor'rgba(23,23,23,0.95)'Color of the backdrop.
    popupfalseCSS selector for an element to open immediately on init.
    ratio'16x9'Aspect ratio: '1x1', '4x3', '16x9', or '21x9'.
    sharefalseEnable share/download/copy link tools.
    shareStyle'pill'Style for share tools: 'bar', 'block', 'pill', or 'transparent'.
    spinner'bounce'Preloader type: 'plane', 'chase', 'bounce', 'wave', 'pulse', 'flow', 'swing', 'circle', 'circle-fade', 'grid', 'fold', 'wander'.
    spinColor'#d2d2d2'Color of the spinner.
    titleattr'title'Attribute used to extract the title.
    titlePosition'top'Position of the title: 'top' or 'bottom'.
    titleStyle'bar'Style for title: 'bar', 'block', 'pill', or 'transparent'.
    toolsBackground'#1C1C1C'Background color for navigation/share tools.
    toolsColor'#d2d2d2'Color for navigation/share tools.
    fitViewfalseWhether to use fit-view logic for content.
    initialScale0.9Initial scale of the content during transition.
    transitionSpeed200Transition speed in ms.
  6. Control VenoBox via API

    master

    The VenoBox instance returned by the constructor provides methods to programmatically control the lightbox:

    • open(obj): Opens a specific element (the obj must be a DOM element).
    • close(): Closes the currently open lightbox.
    • next(): Navigates to the next item in the current gallery.
    • prev(): Navigates to the previous item in the current gallery.

    Access the current configuration via venobox.settings.

    const vbox = new VenoBox();
    
    // Later in your code...
    vbox.open(document.querySelector('.some-link'));
    
    // Or control navigation
    vbox.next();
  7. Use VenoBox lifecycle hooks

    master

    VenoBox provides several callback functions within the options object to hook into the lightbox lifecycle. These allow you to run custom logic at specific stages:

    • onInit(plugin): Called when the plugin is initialized. Receives the plugin instance.
    • onPreOpen(item): Called before an item opens. Return false to prevent opening.
    • onPostOpen(item, gallIndex, thenext, theprev): Called after the lightbox is fully open.
    • onPreClose(item, gallIndex, thenext, theprev): Called before closing. Return false to prevent closing.
    • onNavComplete(item, gallIndex, thenext, theprev): Called after navigation between gallery items is complete.
    • onContentLoaded(newcontent): Called when new content is injected into the lightbox.

    Note: item refers to the DOM element being opened.

    new VenoBox({
      onPreOpen: function(item) {
        console.log('Opening:', item);
        return true; // return false to cancel
      },
      onPostOpen: function(item, gallIndex) {
        console.log('Gallery index:', gallIndex);
      }
    });