Git Product home page Git Product logo

grid-gallery's Introduction

grid-gallery

A simple and light Grid Gallery

Demos

https://jestov.com/grid-gallery/

Usage

  1. Add a link to the css file in your <head>:
<link rel="stylesheet" type="text/css" href="css/grid-gallery.css"/>
// Or for the minified file, add this:
<link rel="stylesheet" type="text/css" href="css/grid-gallery.min.css"/>
  1. On your <body> tag add:
<div class="gg-container">
  <div class="gg-box">
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
</div>
  1. Before your closing <body> tag add:
<script type="text/javascript" src="js/grid-gallery.js"></script>
// Or for the minified file, add this:
<script type="text/javascript" src="js/grid-gallery.min.js"></script>

Multiple Galleries

Can have multiple galleries:

<div class="gg-container">
  <div class="gg-box"> <!-- first gallery --->
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
  
  <div class="gg-box"> <!-- second gallery -->
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
</div>

Settings

Option Type Default Description options
selector string null Element to which the settings are applied to customize the options of a specific gallery ".class", "#id"
darkMode boolean false Enable a dark theme for the gallery true
layout string "vertical" Adapts the layout of the gallery box "horizontal", "square"
gapLength number 2 Modify the thickness in pixels of the gaps between images
rowHeight number 200 Modify the height of images
columnWidth number 220 Customize the width of images

Customize especific gallery

<div class="gg-container">
  <div class="gg-box"> <!-- This gallery takes it the default values -->
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
  
  <div class="gg-box" id="square-dark">
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
  
  <div class="gg-box" id="horizontal-dark">
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
</div>

After the main JS file, add:

gridGallery({
 selector: "#square-dark",
 darkMode: true,
 layout: "square",
 gapLength: 4,
 rowHeight: 180,
 columnWidth: 200
});

gridGallery({
 selector: "#horizontal-dark",
 darkMode: true,
 layout: "horizontal",
 gapLength: 10,
 rowHeight: 150,
 columnWidth: 190
});

Customize multiple galleries

<div class="gg-container">
  <div class="gg-box square-gallery">
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
  
  <div class="gg-box square-gallery">
    <img src="img/your-image-1.jpg">
    <img src="img/your-image-2.jpg">
    <img src="img/your-image-n.jpg">
  </div>
</div>

After the main JS file, add:

gridGallery({
 selector: ".square-gallery",
 layout: "square",
 gapLength: 1,
 columnWidth: 200
});

Credits

All images from Unsplash

grid-gallery's People

Contributors

alnidok avatar jestov 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

Watchers

 avatar  avatar  avatar

grid-gallery's Issues

Navigation buttons bug (2 images only)

If we have 2 images in gallery

<div class="gg-box">
    <img src="img/1.jpg">
    <img src="img/2.jpg">
</div>

and then:

  1. open first image and click next button (prev button is hiding but it should not)
  2. open last image and click prev button (next button is hiding but it should not)

Cannot customize a specific gallery

I made two different configurations at the end of the main.js file:

gridGallery({
 selector: "#main",
 darkMode: false,
 layout: "square",
 gapLength: 0,
 rowHeight: 500,
 columnWidth: 400
});

gridGallery({
 selector: "#main-vertical",
 darkMode: false,
 layout: "vertical",
 gapLength: 1,
 rowHeight: 800,
 columnWidth: 400
});

However, only the top (selector "main") configuration will be loaded.
I want to apply ONLY the second, vertical configuration to my gallery:

     <div class="gg-box" id="main-vertical">
                        <img src="resources/picture/cr1.jpg">
                        <img src="resources/picture/cr2.jpg">
                    </div>

It will just load the square "main" gallery, though...
Any way to get around this?

Thanks!

Not working on iPhone

Hi, tested on PC OK, but on my iPhone 4s touch on tumbnail does nothing. I just see the gallery, but cannot open individual images.

Thumbnail + Full size options?

Firstly thank you for creating this. Absolutely love it!

Feature Request : Ability to specify a thumbnail/small image with a full size image as a popup instead of using full size images as thumbnails. Possibly using data-* attributes for the source of the large image?

<div class="gg-container">
  <div class="gg-box"> 
    <img src="img/thumb/your-image-1-sm.jpg" data-gg-src="img/your-image-1.jpg">
    <img src="img/thumb/your-image-2-sm.jpg" data-gg-src="img/your-image-2.jpg">
    <img src="img/thumb/your-image-3-sm.jpg" data-gg-src="img/your-image-3.jpg">
  </div>
</div>

Directly read images from a folder

Hello,

This a great library. I was wondering if its possible to directly read images from a given folder without specifying the name in the index.html file? Basically, I would like to just put some images in a folder (no fixed format for the name, but must have the same extension like .jpg) and then specify the folder in the index.html file.

P.S.: I am very new to this and have no experience with either HTML and/or javascript, so apologies if the question seems too trivial.

Identifier 'root' has already been declared error

In some cases we need to dynamically write out the script tag for grid-gallery.js (e.g., when used in modals). In this case, if the container is destroyed and recreated, it will throw an "Uncaught SyntaxError: Identifier 'root' has already been declared" error because the constant root is still in memory.

Steps to reproduce:

  1. Go to https://codepen.io/thdoan/pen/yLjjLPw
  2. Launch the modal
  3. Close the modal (click on empty space below)
  4. Launch the modal
  5. Observe the JS error in the console

Fix: wrap everything in an IIFE to preserve variable scope.

(() => {
  const root = document.querySelector("body, html");
  ...
})();

where is options?

Hello ,
thanks for the great stuff , i 've used it and it quite and clean :)
is there any option object , that i can pass properties in to control some aspects for this gallery, something like number of images in rows , or the width of the images and so on .
that would be a great addition.

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.