Coder Social home page Coder Social 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:

<light-box :media="media"></light-box>

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
    autoplay: true //Optional to autoplay video when lightbox opens
  }
]

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 String 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
disableZoom Boolean true set to `true` to avoid zooming 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
showFooterCount Boolean true Show footer count

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: emit when the lightbox is opened.
  • onClosed: emit when the lightbox 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.
  • onImageChanged: Emit when the image is changed.

CREDITS

Most of the CSS belongs to react-images

Contributors:

vue-image-lightbox's People

Contributors

asterisx avatar basuneko avatar carlos-ribeiro-cedro avatar dependabot[bot] avatar djvov avatar gemorroj avatar hasangilak avatar iam-raihan avatar ian-lunasoft avatar imcvampire avatar izshreyansh avatar jstr14 avatar krystalcampioni avatar matewiszt avatar mortenscheel avatar pexea12 avatar purposefuleagle avatar sadortun avatar sammndhr avatar vtalbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-image-lightbox's Issues

no lightBoxOn event !

in my project i'm using lightbox and i need to keep an eye on lightBoxOn to control sidebar show/hide. so it'll be great having lightBoxOn event.

Animation effects

would be nice to chose transition effects (most desirable slide in and out)

Accessibility for images

Looking at the inspected code of the demo and the src it seems you aren't adding an alt tag to the images in the gallery.

It would be rad if the caption attr could translate to an alt tag.

Mem leak

You must destroy hammer created in mounted hook in beforeDestroy hook

SSR options

Hello thanks for the package, already using it in one of my projects.
I do have a question however.

Is there a way to use this package with ssr/nuxt?
If so it would be awesome if the readme contained an example, if not is something that is going to be added?

Remove vue-lazyload as a dependancy

Man I really wanted to love this package, and I was so close. Then I noticed that it's heavily dependent on vue-lazyload. Why? I'm using what I believe is a better lazy load lib (https://github.com/aFarkas/lazysizes) and I'm stuck with the decision on going with a different lightbox or having 2 lazy load libs.

This seems to be a decision I shouldn't have to make.

Can't your comp detect if lazy load is installed and do whatever it needs to?

Responsive Thumbnail Section?

Is there a way the thumbnail section can be responsive? I have seen a few other lightbox examples where depending on the screen size the number of thumbnails changes. Is there a way to do that with this package? or is it something I need to add my own custom CSS/Vue computed property for the nThumbs?

Thanks!

Add ability to zoom

One should be able to pinch-zoom the image.

I would like to contribute, but I need some infos about where to start or where to put this implementation.

Avoid flicker when loading full size images

As opposed to the demo, on my site I'm using different files for thumbnails / full size images. When I open the lightbox or click the next image, for a moment all that's displayed is a little box on the middle of the screen (while the image loads). Is it possible to avoid this?

lightbox

As you can see, after the images are loaded everything works fine.

Missing sourcemap???

Hi,

Tks for nice lightbox.
I wonder if you could provide sourcemap for js file?

Onchange?

Is there any method to know when you change images?

Not working on Ipad

Problem exist on Ipads only. Remote debugger shows next thing

image

This problem discovered on my project (latest build also used). Screen was taken from debugging your demo

Build fails

When doing a npm run build the following error occurs:

ERROR in static/js/vendor.87839b9db02403d7ae6a.js from UglifyJs
Unexpected token: name (s) [./~/vue-image-lightbox/dist/vue-image-lightbox.min.js:1,26466][static/js/vendor.87839b9db02403d7ae6a.js:88596,26426]

ES5 build

Hi,

can you adjust babel so this lib produces ES5 compatible build? This is a nice lib but cannot be used when an app needs to support IE11.

Thanks, Ondrej.

Failed to mount component

After update vue-image-lightbox have error:
"[Vue warn]: Failed to mount component: template or render function not defined.
(found in )"
image

closeLightBox methods

hey,
am really like the package , just need help how using method closeLightBox ?

<lightbox alt="" class="mw-100 w-auto" v-if="data.image" :images="[data.image.full]" ></lightbox>

Could you add onClose event?

This event would fire when the lightbox is closed.

Are there examples of how to work with the events this module provides?
Thank you!

Nuxt Page refresh

Hey I really like this component, but am running into some issues with refreshing the page in my Nuxt app.

image

Here are my dependencies:
"nuxt": "^2.0.0",
"vue-image-lightbox": "^6.0.1",
"vue-lazyload": "^1.2.6",
"vue-touch": "^1.1.0",

and here is the page using the lightbox component

image

I have set up Lazyload as a Nuxt plugin like this

plugins/lazyLoad.js:
import Vue from 'vue'
import VueLazyLoad from 'vue-lazyload'

Vue.use(VueLazyLoad)

nuxt.config.js:
'@/plugins/lazyLoad

What ive tried:

Any help would be greatly appreciated, thanks!

IE11 Issue

Getting an error in IE11 Expected ':'

displayThumbs problem

situation:
After dynamically modification the :images property (add or remove) displayThumbs and countImages properties not updated

TS support

need types support for typescript version....

Lazy Load Large (src) image Only when Gallery Opened / thumbs clicked?

I am using the example with lazy-load (.src) and then openGallery to get Lightbox to show.

Since a typical page may have 20 images or so, and, they could be large, I notice that its the large images (not the thumbs) that are put into the thumb (background on small divs) then when click, it starts lightbox at that image. Which is great. But is there any way to only have the thumbs lazy-loaded, then, when opening lightbox gallery, only then have the full size image lazy loaded, as it's possible not all visitors to the page will even want to click photos.

Here is my code (so maybe it's just a simple adjustment you can recommend, or I've missed something likely, looks great by the way).

<ul class="photoThumbs">
    <li class="thumb-li"
      v-for="(image, index) in images" >
      <div v-lazy:background-image="image.src"  :class="'lazy-thumb'" @click="openGallery(index)">
      </div>

Tried to go with ="image.thumb" but then open LightBox and only get a gallery of the small thumbs. At 8,000 pages with 10 to 20 images per page, and heavy traffic, I'd prefer to download thumbs and only download the large image when someone clicks the thumb or moves to next image in the gallery. Hopefullly I've just not missed something.

TypeError: undefined is not an object (evaluating 't.addEventListener')

I'm getting the following error during page-load:

[Vue warn]: Error in mounted hook: "TypeError: undefined is not an object (evaluating 't.addEventListener')"

found in

---> <Lightbox> at src/components/LightBox.vue
       <Root>

Here's how I am rendering it out:

import LazyLoad from 'vue-lazyload';
import Lightbox from 'vue-image-lightbox';
Vue.use(LazyLoad);
Vue.component("lightbox", Lightbox);
    data: function () {
        return {
            lightboxImages: [],
        };
    },
            <lightbox ref="lightbox" :images="lightboxImages" :show-light-box="false" :show-caption="true"></lightbox>

It appears to have to do with this line:

    const hammer = new Hammer(this.$refs.container)

where this.$refs.container is undefined.
Updating this to the following seems to have worked:

    if (this.$refs.container || false) {
        console.log(this.$refs);
        const hammer = new Hammer(this.$refs.container)

        hammer.on('swiperight', () => {
          this.previousImage()
        })

        hammer.on('swipeleft', () => {
          this.nextImage()
        })
    }

Any thoughts on what may be causing this? It seems to work fine; but I need to clear any errors from the console. Thanks! :)

How to load images using require (as needed by vue.js)

Not a bug or issue, but a question on usage (my apologizes in advance if this is not the right location to ask questions for vue-image-lightbox). I really want to use vue-image-lightbox. How to use 'require' to load .jpg images as needed by Vue.js?

For example (this will show images on page):

          <img
            v-lazy="require(`@/img/${image.src}`)"
            style="height: 100px"
            @click="openGallery(index)"
          >

However, when clicking on an image Lightbox comes up, but images are broken.

Question: How can 'require' be set for the .jpg images for/within <Lightbox...> (so when an images is clicked it will show as expected. Currently images are broken.)?

Thanks much for this tool, and your time.

thumb on dynamic image don't change

I have this template and second thumbs don't change on images change.
The images change correctly but thumbs not work properly.

<template>
  <div>
        <div 
          v-for="(image, index) in products" 
          style="display: inline-block"
          :key="index"
        >
          <img 
            v-lazy="image.link" 
            style="height: 100px" 
            @click="openGallery(index)"
          >
        </div>
      <LightBox 
        :images="images" 
        ref="lightbox"
        :show-thumbs="true"
        :show-light-box="false"
      >
      </LightBox>
    </div>

</template>

<script>
require('vue-image-lightbox/dist/vue-image-lightbox.min.css')
import LightBox from 'vue-image-lightbox'

export default {
  components: {
    LightBox,
  },
  created() {
    console.log('ene0')
  },
  data() {
    return {
      products: [
        { id: 1, link: '/image/1.jpg', images: [
            { id: 1, link: '/image/7.jpg'},
            { id: 2, link: '/image/2.jpg'},
            { id: 3, link: '/image/3.jpg'}
        ]},
        { id: 2, link: '/image/6.jpg', images: [
            { id: 4, link: '/image/4.jpg'},
            { id: 5, link: '/image/5.jpg'},
            { id: 6, link: '/image/6.jpg'}
        ]}
      ],
      images: []
    }
  },
   methods: {
    openGallery(index) {
      this.images = []
      for (let i = 0; i < this.products[index].images.length; i++){
        this.images.push({
          src: this.products[index].images[i].link,
          thumb: this.products[index].images[i].link
        })
      }
      console.log(this.images)
      this.$refs.lightbox.showImage(0)
    }
  }
}
</script>

stopPropagation is not a function

In vue-image-lightbox/dist/vue-image-lightbox in stopPropagation

{snip} .stopPropagation(),t.previousImage()},swipeleft:function(e){e.stopPropagation(),t.nextImage()}}},[s("div",{staticClass:"vue-lb-content"},[s( {snip}

How to use slots?

How do I use the slots.

Currently trying like this, but it does not work:

      <light-box
        :images="lightBoxImages"
      >
        <template v-slot="close">
          <h2>TEST</h2>
        </template>
      </light-box>

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.