Giter VIP home page Giter VIP logo

vue-image-lightbox's Introduction

vue-image-lightbox

A simple image/video lightbox component for Vuejs NPM Package

I use CSS style from react-images

Demo!

Development (NPM / Yarn)

npm run dev
yarn dev

Install

NPM / Yarn

Install the package:

npm install vue-image-lightbox vue-lazyload
yarn add vue-image-lightbox vue-lazyload

Then import it in your project At your entry point (main.js normally)

import Vue from 'vue'
import VueLazyLoad from 'vue-lazyload'
...
Vue.use(VueLazyLoad)

and use the lightbox:

import LightBox from 'vue-image-lightbox'

export default {
  components: {
    LightBox,
  },
}

Browser global

<script src="path/to/vue.js"></script>
<script src="path/to/dist/vue-image-lightbox.js"></script>

Usage

You can simply view App.vue to see how to use vue-image-lightbox

Import CSS style

require('vue-image-lightbox/dist/vue-image-lightbox.min.css')
// Use only when you are using Webpack

How to use:

<LightBox :media="media"></LightBox>

media has the structure:

[
  { // For image
    thumb: 'http://example.com/thumb.jpg',
    src: 'http://example.com/image.jpg',
    caption: 'caption to display. receive <html> <b>tag</b>', // Optional
    srcset: '...' // Optional for displaying responsive images
  },
  { // For video
    thumb: 'https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg',
    sources: [
      {
        src: 'https://www.w3schools.com/html/mov_bbb.mp4',
        type: 'video/mp4'
      }
    ],
    type: "video",
    caption: '<h4>Monsters Inc.</h4>',
    width: 800, // required
    height: 600, // required
  }
]

Options

Properties

name type default description
media Array required Media array to display
showLightBox Boolean true Whether to show lightbox or not at the beginning
startAt Number 0 Index of the image that you want to start at
nThumbs Number 7 Number of thumbnail images
showThumbs Boolean true Whether to show thumbnails or not
autoPlay Boolean false Move to next image automatically
autoPlayTime Number 3000 (ms) Time to stop at an image before move on to next image
siteLoading null default image when your image is error or loading
showCaption Boolean false Whether to show caption or not
disableScroll Boolean true set to `true` to avoid scrolling views behind lightbox
lengthToLoadMore Number 0 Minimum length unto end to emit load more event
closable Boolean true Display the close button at the right top corner or not. ESC clicking-close will also be disabled if closable is set to false.
closeText String Close (Esc) Text for the close button
previousText String Previous Text for the previous image button
nextText String Next Text for the next image button
previousThumbText String Previous Text for the previous thumb image button
nextThumbText String Next Text for the next thumb image button

Methods

name arguments description
nextImage () Move to next image
previousImage () Move to previous image
closeLightBox () Close lightbox
showImage (index) Show the image at index

Slots

close

The content of the close button.

footer

The content of the footer under the image.

slot-scopes
name type description
current integer Number of the current image displayed
total integer Numbers of the images

previous

The previous button on the main image.

next

The next button on the main image.

previousThumb

The previous button on the thumbs list.

nextThumb

The next button on the thumbs list.

customCaption

The caption of the current image.

videoIcon

The Icon used for videos

Events

  • onOpened(value): true to emit when the lightbox is opened and false when it is closed.
  • onLastIndex: Emit when the current image is the last one of the list.
  • onFirstIndex: Emit when the current image is the first one of the list.
  • onStartIndex: Emit when the current image is at the startAt index (specified in the properties).
  • onLoad: Emit when there are lengthToLoadMore images left in the array (specified in the properties). For example, if lengthToLoadMore = 2 and there are 7 images in your array, when you reach index 4 (which means there are 2 images left which are not discovered yet), this event will be emitted. After that, if the image array are updated and there are totally 15 images, the event will be emitted at index 12.

CREDITS

Most of the CSS belongs to react-images

Contributors:

vue-image-lightbox's People

Contributors

asterisx avatar basuneko avatar dependabot[bot] avatar djvov avatar gemorroj avatar hasangilak avatar iam-raihan avatar ian-lunasoft avatar imcvampire avatar jstr14 avatar krystalcampioni avatar matewiszt avatar mortenscheel avatar pexea12 avatar sadortun avatar vtalbot 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.