Giter Site home page Giter Site logo

onecruz / baguettebox.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from feimosi/baguettebox.js

0.0 1.0 0.0 15.26 MB

:zap: Simple and easy to use lightbox script written in pure JavaScript

Home Page: https://feimosi.github.io/baguetteBox.js/

License: MIT License

JavaScript 88.85% CSS 11.15%

baguettebox.js's Introduction

baguetteBox.js

GitHub Release MIT License dependency Status devDependency Status npm Build Status

Twitter Twitter Follow

Simple and easy to use lightbox script written in pure JavaScript.

Demo page

Demo Page screenshot

Features

  • Written in pure JavaScript, no dependencies required
  • Multiple-gallery support allows custom options for each
  • Supports swipe gestures on touch-screen devices
  • Full-screen mode available
  • Modern and minimal look
  • Image captions support
  • Responsive images
  • CSS3 transitions
  • SVG buttons, no extra files to download
  • Around 3.2KB gzipped

Installation

You can use one of the following methods:

npm

npm install baguettebox.js --save

Yarn

yarn add baguettebox.js

Bower

bower install baguettebox.js --save

CDN

  1. Use one of the following CDN providers:
  1. Copy URLs of the latest version (both .js and .css files)

  2. Paste the URLs in your HTML file:

<link rel="stylesheet" href="<CSS URL>">
<script src="<JS URL>" async></script>

Manually

  1. Download baguetteBox.min.css and baguetteBox.min.js files from the dist folder.
  2. Include them somewhere in your document:
<link rel="stylesheet" href="css/baguetteBox.min.css">
<script src="js/baguetteBox.min.js" async></script>

Usage

Initialize the script by running:

baguetteBox.run('.gallery');

where the first argument is a selector to a gallery (or galleries) containing a tags. The HTML code may look like this:

<div class="gallery">
    <a href="img/2-1.jpg" data-caption="Image caption">
        <img src="img/thumbnails/2-1.jpg" alt="First image">
    </a>
    <a href="img/2-2.jpg">
        <img src="img/thumbnails/2-2.jpg" alt="Second image">
    </a>
    ...
</div>

To use captions put a title or data-caption attribute on the a tag.

Customization

You can pass an object with custom options as the second parameter.

baguetteBox.run('.gallery', {
    // Custom options
});

The following options are available:

Option Type Default Description
captions Boolean | function(element) true Display image captions. Passing a function will use a string returned by this callback. The only argument is a element containing the image. Invoked in the context of the current gallery array
buttons Boolean | 'auto' 'auto' Display buttons. 'auto' hides buttons on touch-enabled devices or when only one image is available
fullScreen Boolean false Enable full screen mode
noScrollbars Boolean false Hide scrollbars when gallery is displayed
bodyClass String 'baguetteBox-open' Class name that will be appended to the body when lightbox is visible (works in IE 10+)
ignoreClass String null It will ignore images with given class put on a tag
titleTag Boolean false Use caption value also in the gallery img.title attribute
async Boolean false Load files asynchronously
preload Number 2 How many files should be preloaded
animation 'slideIn' | 'fadeIn' | false 'slideIn' Animation type
afterShow function null Callback to be run after showing the overlay
afterHide function null Callback to be run after hiding the overlay
onChange function(currentIndex, imagesCount) null Callback to be run when image changes
overlayBackgroundColor String 'rgba
(0,0,0,0.8)'
Background color for the lightbox overlay
filter RegExp /.+\.(gif|jpe?g|png|webp)/i Pattern to match image files. Applied to the a.href attribute

API

  • run - initialize baguetteBox.js
  • showNext - switch to the next image
  • showPrevious - switch to the previous image
  • destroy - remove the plugin with any event bindings

showNext and showPrevious return true on success or false if there are no more images to be loaded.

Responsive images

To use this feature, simply put data-at-{width} attributes on a tags with a value being the path to the desired image. {width} should be the maximum screen width the image can be displayed at. The script chooses the first image with {width} greater than or equal to the current screen width for best user experience. That last data-at-X image is also used in the case of a screen larger than X.

Here's an example of what the HTML code can look like:

<a href="img/2-1.jpg"
  data-at-450="img/thumbs/2-1.jpg"
  data-at-800="img/small/2-1.jpg"
  data-at-1366="img/medium/2-1.jpg"
  data-at-1920="img/big/2-1.jpg">
    <img src="img/thumbs/2-1.jpg">
</a>

If you have 1366x768 resolution baguetteBox.js will choose "img/medium/2-1.jpg". If, however, it's 1440x900 it'll choose "img/big/2-1.jpg". Keep the href attribute as a fallback (link to a bigger image e.g. of HD size) for older browsers.

Compatibility

Desktop:

  • IE 8+
  • Chrome
  • Firefox 3.6+
  • Opera 12+
  • Safari 5+

Mobile:

  • Safari on iOS
  • Chrome on Android

Contributing

Feel free to report any issues! If you wish to contribute by fixing a bug or implementing a new feature, please first read the CONTRIBUTING guide.

Credits

Creation of baguetteBox.js was inspired by a great jQuery plugin touchTouch.

License

Copyright (c) 2017 feimosi

This content is released under the MIT License.

baguettebox.js's People

Contributors

feimosi avatar xhmikosr avatar h-lo avatar louy avatar romanhotsiy avatar leomelzer avatar chi-teck avatar davidhellmann avatar edkf avatar o-klp avatar lorenzck avatar leibrug avatar rgalanakis avatar terrytilley avatar tobaco avatar

Watchers

 avatar

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.