Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jlozovei/simple-image-gallery

VanillaJS simple+fancy image gallery :zap:
https://github.com/jlozovei/simple-image-gallery

gallery image-gallery vanilla-js

Last synced: about 1 month ago
JSON representation

VanillaJS simple+fancy image gallery :zap:

Awesome Lists containing this project

README

        

# Simple Image Gallery

No dependencies, no libs, no frameworks - a simple and fancy image gallery, crafted with a few lines of pure JavaScript!

- [jlozovei.github.io/simple-image-gallery](https://jlozovei.github.io/simple-image-gallery)
- [codepen.io/jlozovei/simple-image-gallery](https://codepen.io/jlozovei/pen/eLdzNY)

### How To:

To use this simple gallery, just add the next markups:

#### HTML:
```html


```

#### JS:
```js
const galleryWrapper = document.getElementById('gallery'),
galleryControllers = galleryWrapper.querySelectorAll('.gallery__controller')

galleryControllers.forEach(controller => {
controller.addEventListener('click', () => {
if(controller.classList.contains('gallery__controller--prev'))
galleryGoBack()
else
galleryGoForward()
})
})

function galleryGoBack(){
const active = galleryWrapper.querySelector('img.active')
active.classList.remove('active')

if(active.previousElementSibling)
active.previousElementSibling.classList.add('active')
else
this.galleryWrapper.querySelector('img:last-child').classList.add('active')
}

function galleryGoForward(){
const active = galleryWrapper.querySelector('img.active')
active.classList.remove('active')

if(active.nextElementSibling)
active.nextElementSibling.classList.add('active')
else
this.galleryWrapper.querySelector('img').classList.add('active')
}
```

### Cloning this repo
Also, you can clone/download this repo to change `HTML`, `CSS` and/or `JS` files locally. To do so:

```bash
# clone repo
git clone https://github.com/jlozovei/simple-image-gallery.git

# install dependencies
yarn

# serve with hot reload at localhost:9797
gulp
```