Install

All of the files that you need to work with are in the Main folder. In order to install the gallery on your html page, you will need to do the following steps:

1. Copy the gallery assets folder, "nice-gallery", and add it next to your html file.

2. Copy the gallery html code and add it to your html file:

Select a template and open it in a text editor.

a. Copy the assets code and add it at the end of the <head> tag on your html page.

b. Copy the markup code and add it in the <body> tag on your html page.

c. Copy the build code and add it at the end of the <body> tag on your html page.

Detailed instructions

1. Copy the gallery assets folder, "nice-gallery", and add it next to your html file.

This folder contains the files needed by the gallery such as the CSS, JavaScript and image files. The folder needs to be with your html file so that the gallery can load the necessary assets.

2. Copy the gallery html code and add it to your html file:

There are multiple templates that the gallery comes with, which provide a starting point in customizing it. Once you have decided which template to use, open the html file in a code/text editor.

If you do not have a code editor, I use and recommend Sublime Text. It is a great editor and it is free to use.

After you open the file in an editor, you will see that the needed gallery code is nicely shown by comments:

a. Copy the assets code and add it at the end of the <head> tag on your html page.

<!-- Start of gallery assets code -->
<link href="nice-gallery/css/nice-gallery.css" type="text/css" rel="stylesheet">
<script src="nice-gallery/js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="nice-gallery/js/velocity.min.js" type="text/javascript"></script>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" ...></script> -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.5.0/velocity.min.js" ...></script> -->
<script src="nice-gallery/js/jquery.nice-gallery.min.js" type="text/javascript"></script>
<!-- End of gallery assets code -->

This code specifies the necessary files to be loaded by the page.

Important: Lines 3 and 4 from above load jQuery and Velocity. If you already have any of them on the page, do not add them again. But make sure that they are added on the page before the gallery JS file (line 7).

Optional: Lines 5 and 6 are commented out. These are alternative ways of loading jQuery and Velocity, from CDNs (Content Delivery Networks). The reason why you would want this is because the loading times would be faster for the user if he were to load the files from a CDN server rather than from your own site. Or, if the user visited sites using the same practice, he might already have the files already cached in his browser. I have added these as a useful option for people who want them, but I have not enabled them by default because it will always require an Internet connection to preview the gallery. But, when deploying it on the web, it is not a bad idea to use these faster loading options instead.

b. Copy the markup code and add it in the <body> tag on your html page.

<!-- Start of gallery markup code -->
<div class="nice-gallery">
    <div class="ng-head">
        <div class="ng-title">An album of great places to visit next summer</div>
        ...
    </div>
    <div class="ng-body">
        <ul class="ng-slides">
            <li>
                <img src="nice-gallery/images/image1.jpg" alt="Image 1">
                <div class="ng-desc">
                    <div class="ng-name">1. Lorem ipsum dolor sit amet, consectetuer adipiscing aenean elit quis</div>
                    <div class="ng-text">Commodo ligula eget dolor aenean massa sociis natoque penatibus et ...</div>
                </div>
            </li>
        ...
</div>
<!-- End of gallery markup code -->

This is the bulk of the gallery html code and it specifies all of the content of the gallery, such as images, descriptions and thumbs.

c. Copy the build code and add it at the end of the <body> tag on your html page.

<!-- Start of gallery build code -->
<script type="text/javascript">
    jQuery(document).ready(function() {

        jQuery(".nice-gallery").niceGallery({
            // Image
            imageEffect: "slide",
            imageAnimate: [400, "easeOutQuad"],
            frameRatio: false,
            ...
        });
        
    });
</script>
<!-- End of gallery build code -->

This is the JavaScript code that builds the gallery functionality by calling the plugin and passing the settings to it.

To see all of the available settings, their meanings and possible values, see the Settings table.

Now that you have the gallery up and running on your page, you can start to customize it as you like.

Customize

This section contains a few specific customizations. For other customizations, see the Settings or edit the CSS file directly.

Add images

An image is an <li> element inside <ul class="ng-slides">:

<li>
    <img src="nice-gallery/images/image1.jpg" alt="Image 1">
    <div class="ng-desc">
        <div class="ng-name">1. Lorem ipsum dolor sit amet, consectetuer adipiscing aenean elit quis</div>
        <div class="ng-text">Commodo ligula eget dolor aenean massa sociis natoque penatibus et magnis dis ...</div>
    </div>
</li>

The ng-desc element is optional and can be omitted if there is no description for the image.

The thumb is added as an <li> element inside <ul class="ng-thumbs">:

<li><img src="nice-gallery/images/thumb1.jpg" alt="Thumb 1"></li>

Change width

The gallery width is set from the CSS file:

.nice-gallery {
    ...
    max-width: 758px;
}

When the thumbs are underneath, it is recommended to have this dimension a multiplication of the thumb size, so that the thumbs align well.

For example, by default, there are 11 thumbs in a line underneath, each having 60px width and 3px right margin. If the gallery arrows are on the outside, the padding of 34px on each side should be accounted as well.

60px * 11 + 3px * 10 + 34px * 2 = 758px

Description width

This applies to when the image description is on the side.

The description width can be changed from the CSS file:

.ng-side-desc .ng-desc {
    width: 220px;
    ...
}

Thumbs width

This applies to when the thumbs panel is on the side.

The width of the thumbs panel is can be changed from the CSS file:

.ng-side-thumbs .ng-thumbs {
    width: 189px;
    ...
}

The width should be calculated based on the number of thumb columns that you want to have. By default, there are 3 columns. A thumb has 60px width and 3px right margin.

60px * 3 + 3px * 3 = 189px (The space is used 3 times because of the negative right margin of the thumbs panel.)

Arrows color

The navigation arrows are .png images and by default, the gallery comes with 2 sets of arrows, one black and one white.

When the arrows are on the outside, the black color is used, when the arrows are on the insde, the white color is used.

Which version is used can be changed from the CSS file:

.ng-prev {
    background-image: url("img/prev-white.png");
    ...
}
.ng-next {
    background-image: url("img/next-white.png");
    ...
}
.ng-outside-arrows .ng-prev {
    background-image: url("img/prev-black.png");
    ...
}
.ng-outside-arrows .ng-next {
    background-image: url("img/next-black.png");
    ...
}

Additionally, the sources of the image files are included in the Sources/img folder and they can be used to make the arrows any color that is needed.

Settings

The settings are placed in the JavaScript build code:

jQuery(".nice-gallery").niceGallery({
    // Image
    imageEffect: "slide",
    imageAnimate: [400, "easeOutQuad"],
    frameRatio: false,
    ...
});

The table below shows all of the settings that are available, their default and possible values, as well as a description about each.

It is not necessary to specify all of the settings in the build code. When a setting is not specified, it will automatically take the default value.

Name Default value Possible values
// Image
imageEffect "slide" "fade", "slide", "quickSlide", "stack", "none"

The display effect of the images.

imageAnimate [400, "easeOutQuad"] [<time>, <ease>]

The animation parameters of the image.

The time is in milliseconds and for the easing, see the Ease options at the bottom of the table.

frameRatio false <float number>, false

The ratio between the width and height of the image container.

This can be used to have a constant frame size for all images.

If set to false, the frame height will automatically resize based on the height of the image.

descEnabled true true, false

If the image descriptions should be enabled.

descPosition "under" "under", "side"

The position of the image descriptions.

// Thumbs
thumbsEnabled true true, false

If the thumbs should be enabled.

thumbsPosition "under" "under", "side"

The position of the thumbs panel.

thumbBorderEnabled true true, false

If the thumbs border should be enabled.

This is shown on mouseover and when a thumb is selected.

thumbBorderType "box" "box", "top", "bottom"

The type of the thumb border.

Have a border around the whole thumb, or only on the top or on the bottom.

// Arrows
arrowsEnabled true true, false

If the left and right navigation arrows should be enabled.

arrowsPosition "outside" "outside", "inside"

The position of the navigation arrows, either on the outside or inside the image frame.

insideArrowColor "white" "white", "black"

The color of the navigation arrows when they are on the inside.

The arrows are image files and these are the colors included by default. You can use the source files from the Sources/img folder of the downloaded project files to make the arrows any color that you want.

outsideArrowColor "black" "white", "black"

The color of the navigation arrows when they are on the outside.

The arrows are image files and these are the colors included by default. You can use the source files from the Sources/img folder of the downloaded project files to make the arrows any color that you want.

// Scroll
scrollToImage true true, false

If the page should scroll to the image if it is not in view on the page when it is opened.

scrollDevice "mobile" "all", "computer", "mobile"

The devices for which the page should scroll to the image.

scrollAnimate [500, "swing"] [<time>, <jQuery ease>]

The animation parameters of the page scrolling.

The time is in milliseconds and the jQuery easing possible values are "linear" and "swing".

// Other
loop true true, false

If the gallery should loop from the last image to the first and vice-versa.

keyboardArrows true true, false

If the left and right keyboard arrows should be used for navigation.

responsive true true, false

If the gallery should be responsive and resize automatically based on the available space.

autoplay false <milliseconds>, true, false

If the gallery should autoplay and switch images automatically at an interval of time.

The time is expressed in milliseconds. When set to true, the default time is 5000 ms (5 seconds).

defaultOpen 1 <number>

The order number of the image opened by default.

// Lightbox
lightboxEnabled true true, false

If the lightbox functionality should be enabled. This opens an image in a bigger view when it is clicked.

lightboxDevice "all" "all", "computer", "mobile"

The devices for which the lightbox should be enabled.

lightboxDesc true true, false

If the lightbox should display the image description text.

lightboxArrows true true, false

If the lightbox should have the prev and next navigation arrows.

lightboxDescHide true true, false

If the lightbox should have the description text hidden by default and shown on mouseover.

lightboxControlsHide true true, false

If the lightbox should have the controls (close button and navigation arrows) hidden by default and shown on mouseover.

lightboxControlsColor "white" "white", "black"

The color of the lightbox controls (close button and navigation arrows).

The controls are image files and these are the colors included by default. You can use the source files from the Sources/img folder of the downloaded project files to make the controls any color that you want.

lightboxAnimate [200, "easeOutQuad"] [<time>, <ease>]

The animation parameters of the lightbox.

The time is in milliseconds and for the easing, see the Ease options at the bottom of the table.

lightboxOnClick "close" "next", "close"

What should happen when the lightbox image is clicked, either show the next image or close the lightbox.

lightboxImageUrls null [<list if image URLs>]
["nice-gallery/images/image1.jpg", "nice-gallery/images/image2.jpg", ...]

By default, the lightbox automatically takes the image URLs from the src attribute of <img> elements. But, if you are using a lazy loader plugin that sets the images src attributes to empty, then you can use this setting to specify the image URLs for the lightbox.

Ease options

The available ease values for the animation settings are the following:

    • easeInSine
    • easeOutSine
    • easeInOutSine
    • easeInQuad
    • easeOutQuad
    • easeInOutQuad
    • easeInCubic
    • easeOutCubic
    • easeInOutCubic
    • easeInQuart
    • easeOutQuart
    • easeInOutQuart
    • easeInQuint
    • easeOutQuint
    • easeInOutQuint
    • easeInExpo
    • easeOutExpo
    • easeInOutExpo
    • easeInCirc
    • easeOutCirc
    • easeInOutCirc
    • ease
    • ease-in
    • ease-out
    • ease-in-out
    • spring

Methods

The methods are called through the JS code. The following are all of the available methods, how to call them and what they do:

  • open
    jQuery(".nice-gallery").niceGallery("open", 5);
    Opens an image based on the order number supplied.
  • prev
    jQuery(".nice-gallery").niceGallery("prev");
    Opens the previous image.
  • next
    jQuery(".nice-gallery").niceGallery("next");
    Opens the next image.
  • startAutoplay
    jQuery(".nice-gallery").niceGallery("startAutoplay");
    Starts the autoplay.
  • stopAutoplay
    jQuery(".nice-gallery").niceGallery("stopAutoplay");
    Stops the autoplay.
  • scrollPage
    jQuery(".nice-gallery").niceGallery("scrollPage", 100, true);
    Scrolls the page to a certain position using the scroll animate settings.
    The first parameter specifies the page position to scroll to (in pixles). The second parameter specifies if to animate the scrolling.
  • onPageScroll
    jQuery(".nice-gallery").niceGallery("onPageScroll", function() {...});
    Adds a function to be called when the page scrolls.
  • onPageAutoScrollFinish
    jQuery(".nice-gallery").niceGallery("onPageAutoScrollFinish", function() {...});
    Adds a function to be called when the page automatic scroll finishes.
  • destroy
    jQuery(".nice-gallery").niceGallery("destroy");
    Destroys the gallery. Removes everything that was built when the gallery was initially created.

I have a problem

If you have a problem with the gallery, a few common things to do are:

  • Make sure that jQuery is not added multiple times on the page.
    If you already have jQuery on your page, remove it from the gallery assets code. But make sure that your jQuery is added before any gallery JS file.
  • Open the browser developer tools (F12) and see if there are any errors shown in the console.
    If there are any error messages shown, try to read and understand what they say. Try to google them to find out more information about what they mean or send the messages to me and I will explain them to you.
  • Have a look over the gallery message board, in case the problem has been discussed before and solved.
  • Make sure that you have added all of the gallery code (assets, markup, build) to your page.
  • Make sure that all of the used files are accessible and loading well (CSS, JS, images).

If you cannot fix the problem, contact me and I will help you. If possible, it would be useful if you could send me a link to where I can look over your implementation so that I can give you specific feedback. If it is not possible to send me a link, just describe the problem to me and I will try to replicate it on my end.

Contact

If you have any questions or need some help, please contact me.

The fastest way that you can get in touch with me is to simply send me an email at contact@creativetier.com.

Another option to send me a message is to use the contact form on my CodeCanyon profile page.

Or you can simply post a message on the gallery message board and I will answer you there.

Credits

Many thanks to the following: