Contents

Install

All of the files that you need to work with are in the Gallery folder.

In order to install the gallery on your html page, you will need to do the following steps:

Quick instructions

1. Copy the gallery assets folder, sharp-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> of your html page, where you want the gallery to be displayed.

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

Detailed instructions

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

This folder contains the files needed by the gallery such as the CSS, JavaScript, jQuery files (among others) and, of course, the images themselves. 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 text editor.

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

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="sharp-gallery/css/sharp-gallery.css" type="text/css" rel="stylesheet">
<script src="sharp-gallery/js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="sharp-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="sharp-gallery/js/jquery.sharp-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: Line 3 from above loads jQuery. If you already have jQuery on the page, do not add it a second time as this might create problems. Simply delete this line. But make sure that jQuery is added on the page before this block of code.

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 a site using the same practice, he might already have jQuery or Velocity 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. If you use lines 5 and 6 to load jQuery and Velocity (by removing the comments at the beginning and end) remember to delete lines 3 and 4 as not to load them two times.

b. Copy the markup code and add it in the <body> of your html page, where you want the gallery to be displayed.

<!-- Start of gallery markup code -->
<div class="sharp-gallery">
    <div class="sg-head">
        <div class="sg-title">Amazing photos from all around the world</div>
        ...
    </div>
    <div class="sg-body">
        <div data-id="image1">
            <img src="sharp-gallery/images/thumb1.jpg" alt="Thumb 1">
            <div class="sg-label">1. Valley of the Gods</div>
        </div>
        ...
    </div>
    ...
</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, from images and thumbs to the title, names and descriptions.

After you are done with the installation, you should look at The markup code section to learn how to customize this code and how to add your own images.

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

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

        jQuery(".sharp-gallery").sharpGallery({
            // Main
            width: 797,
            margin: [30, "auto"],
            ...
        });

    });
</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 here, 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 want it.

Customize

When customizing the gallery, you can change the markup code to customize the content of the gallery, you can change the settings to customize the functionality, you can edit the CSS file to change anything about the look that you want, and for more advanced users, you can also edit the gallery JavaScript file.

Markup code

The markup code specifies all of the content of the gallery, such as images, thumbs, description texts, thumb labels, gallery title and so on.

<!-- Start of gallery markup code -->
<div class="sharp-gallery">
    <div class="sg-head">
        <div class="sg-title">Amazing photos from all around the world</div>
        ...
    </div>
    <div class="sg-body">
        <div data-id="image1">
            <img src="sharp-gallery/images/thumb1.jpg" alt="Thumb 1">
            <div class="sg-label">1. Valley of the Gods</div>
        </div>
        ...
    </div>
    <div class="sg-data">
        <div data-id="image1" data-src="sharp-gallery/images/image1.jpg" data-alt="Image 1">
            <div class="sg-text">
                <div class="sg-name">1. The Valley of the Gods</div>
                <div class="sg-desc">Lorem ipsum dolor sit amet consectetuer adipiscing elit aenean commodo ...</div>
                <div class="sg-info">photo by <a href="http://www.creativetier.com" target="_blank">Guy ...</div>
            </div>
        </div>
        ...
    </div>
</div>
<!-- End of gallery markup code -->

This code has 3 main sections: head, body and data.

Head section
<div class="sg-head">
    <div class="sg-title">Amazing photos from all around the world</div>
    <div class="sg-subtitle">We have put together an album of some amazing photos that are sure to delight ...</div>
    <div class="sg-tag">by <a href="http://www.creativetier.com" target="_blank">Guy McWriterson</a></div>
    <div class="sg-tag">on 15/08/2016</div>
</div>

The head contains the title, subtitle and tags. All of these are optional for the gallery, you can remove any of the elements from the head, or you can remove the whole head element, if you want to.

Body section
<div class="sg-body">
    <div data-id="image1">
        <img src="sharp-gallery/images/thumb1.jpg" alt="Thumb 1">
        <div class="sg-label">1. Valley of the Gods</div>
    </div>
    ...
</div>

The body contains the list of thumbs. (Later on, when an image is opened, the stage - the big area that displays an image - will also be dynamically added to the body and positioned automatically where it is needed.)

The code for a thumb is a <div> element with a data-id attribute. This represents the id of the image and when a thumb is clicked, this id is used to know what image data to retrieve and display.

The thumb contains an <img> element with the path to the thumb image file, as well as the alt text, and a <div> element with the text label that appears over the thumb. The label is optional, if you don't want it displayed over the thumb, you can simply remove this element.

Data section
<div class="sg-data">
    <div data-id="image1" data-src="sharp-gallery/images/image1.jpg" data-alt="Image 1">
        <div class="sg-text">
            <div class="sg-name">1. The Valley of the Gods</div>
            <div class="sg-desc">Lorem ipsum dolor sit amet consectetuer adipiscing elit aenean commodo ...</div>
            <div class="sg-info">photo by <a href="http://www.creativetier.com" target="_blank">Guy McPictureson ...</div>
        </div>
    </div>
    ...
</div>

The data section contains the information necessary when opening the images. When an image is opened, the data for that image is taken from here and used when displaying the image.

The code for an image is a <div> element with a unique data-id attribute. It also has data-src and data-alt attributes as the path and alt text for the image itself.

The element contains a <div> with the overlay text. Within, there are multiple lines of text. Each line is optional, you can keep the ones you want and remove the ones you don't need. Also, the whole text element is optional. If you don't want any text over the image, you can simply remove the whole text div and let the image element empty.

To add an image to the gallery, you simply add the thumb code in the body section, the image code in the data section and the thumb and image files to the sharp-gallery/images folder.

Settings

These are settings that you place in the JavaScript build code:

jQuery(".sharp-gallery").sharpGallery({
    // Main
    width: 797,
    margin: [30, "auto"],
    ...
});

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 Description
// Main
width 797
Number
false
The maximum width of the gallery, in pixels.
If there is less space available, it resizes accordingly.
If you don't want to have a maximum width and want the gallery to fill all of the available space, you can simply set this to false or 0.
margin [30, "auto"]
Number
[30, 50]
[30, "auto"]
[30, 50, 30, 50]
false
The margins around the gallery.
The value can be a number to have the same margin on all sides or an array containing the margin values for each side.
The array can contain 1, 2, 3 or 4 values and follows the notation convention of the CSS margin property: 1 value for the margin on all sides; 2 values for top & bottom, left & right; 3 values for top, left & right, bottom; and 4 values for each side.
Additionally, the "auto" value can also be used. Specifying "auto" for the margins on left and right will horizontally center the gallery.
If you don't want to have any margins, you can simply set this to false or 0.
// Thumbs
thumbWidth 157
Number
The maximum width of a thumb, in pixels. (The exact width can differ because the thumbs have to fill all of the available space.)
The gallery calculates how many thumbs are needed to fill the available space, this value being the maximum width allowed. That gives the number of thumb columns. Then the exact width is determined by dividing the gallery width to the number of columns.
Applicable when thumbColumns is set to "auto".
thumbRatio 1.5
Number
"3:2"
"157x104"
The ratio between the width and height of the thumb.
This is to specify the height of the thumb. Because the thumb width is dynamic and can vary based on the gallery width and number of columns, the height is also expressed in a dynamic way, in the form of a ratio.
The ratio can be expressed in different formats, like 1.5, "3:2" or "157x104".
thumbColumns "auto"
"auto"
Number
"4, 3: <=600, 2: <=400"
The number of columns of thumbs.
If set to "auto", the number of columns is automatically calculated based on the thumbWidth setting.
It can be set to a Number to determine an exact number of columns.
Or to an expression such as "4, 3: <=600, 2: <=400" to specify different number of colums based on the gallery width. What this expression means is that the thumbs will have 4 colums by default, 3 columns if the gallery width is less or equal to 600px and 2 columns if the gallery width is less or equal to 400px.
thumbImageScale "fill"
"fill"
"fit"
"stretch"
The way the image scales within the thumb.
If set to "fill", it will scale to fill all of the available space, while maintaining the aspect ratio.
If set to "fit", it will scale to fit in the available space and and will be centered. It will also maintain the aspect ratio.
If set to "stretch", the image will scale to the exact dimensions of the thumb and the aspect ratio will not be kept.
thumbLabelHide false
true
false
If the thumb text label should be hidden by default and shown when mousing over the thumb.
thumbLabelSelected true
true
false
If the thumb label should be selected (and visible) when the thumb is selected.
Applicable when thumbLabelHide is set to true.
thumbLabelBackground "gradient"
"gradient"
"plain"
The background type of the thumb label, either "gradient" or "plain".
thumbLabelAnimate [130, "easeOutQuad"]
[Milliseconds, Ease]
Milliseconds
Ease
true
false
The animation parameters of the thumb label.
The normal value is an array containing the duration of the animation, in milliseconds, and the animation ease: [130, "easeOutQuad"].
It is possible to specify only the Milliseconds or only the Ease and the other respective parameter will be added automatically from the default value.
If set to true, it will automatically apply the default value.
If set to false, there will be no animation effect.
For all of the available easing values, see the Easing options at the bottom of the table.
Applicable when thumbLabelHide is set to true.
thumbLabelsEnabled true
true
false
If the thumb labels should be enabled and displayed.
This is a useful option to have when customizing the gallery to be able to switch easily between displaying thumb labels and not, without needing to modify any HTML code.
thumbOverBorder true
true
false
If the thumbs should show the border when mousing over them.
thumbSelectedBorder true
true
false
If the thumbs should show the border when they are selected.
thumbBorderType "line"
"line"
"box"
The border type of the thumb, either "line" to show a line border, on top or on bottom, depending on the position of the stage, or "box" to show a border around the whole thumb.
thumbBorderWidth "small"
"small"
"big"
The width of the thumb border, either "small" (3px) or "big" (4px).
thumbBorderCorners "square"
"square"
"round"
The corners type of the thumb border, either "square" or "round".
thumbBorderArrow true
true
false
If the thumb border should show an arrow when the thumb is selected. The arrow is shown either on top or on the bottom, depending on the position of the stage.
Applicable when thumbSelectedBorder is set to true.
thumbBorderAnimate [130, "easeOutQuad"]
[Milliseconds, Ease]
Milliseconds
Ease
true
false
The animation parameters of the thumb border.
The normal value is an array containing the duration of the animation, in milliseconds, and the animation ease: [130, "easeOutQuad"].
It is possible to specify only the Milliseconds or only the Ease and the other respective parameter will be added automatically from the default value.
If set to true, it will automatically apply the default value.
If set to false, there will be no animation effect.
For all of the available easing values, see the Easing options at the bottom of the table.
Applicable when thumbOverBorder or thumbSelectedBorder are set to true.
thumbSpace "small"
"small"
"big"
The space between the thumbs, either "small" (3px) or "big" (5px).
thumbDeselect true
true
false
If it is possible to deselect a thumb by clicking it when it is selected.
// Stage
stageRatio false
Number
"3:2"
"800x533"
false
The ratio between the width and the height of the stage. (The stage is the big area in which the images are shown.)
The stage width is automatic, based on the width of gallery and this is a dynamic way to specify the stage height.
The ratio can be expressed in different formats, like 1.5, "3:2" or "800x533".
If it is set to false, the height of the stage is automatic, based on the height of the image opened.
stagePosition "over"
"over"
"under"
"top"
The position of the stage, either "over" the selected thumb, "under" the selected thumb or on "top" of the whole thumbs.
stageAnimate [500, "easeOutQuad"]
[Milliseconds, Ease]
Milliseconds
Ease
true
false
The animation parameters of the stage.
The normal value is an array containing the duration of the animation, in milliseconds, and the animation ease: [500, "easeOutQuad"].
It is possible to specify only the Milliseconds or only the Ease and the other respective parameter will be added automatically from the default value.
If set to true, it will automatically apply the default value.
If set to false, there will be no animation effect.
For all of the available easing values, see the Easing options at the bottom of the table.
imageAnimate [500, "easeOutQuad"]
[Milliseconds, Ease]
Milliseconds
Ease
true
false
The animation parameters of the image.
The normal value is an array containing the duration of the animation, in milliseconds, and the animation ease: [500, "easeOutQuad"].
It is possible to specify only the Milliseconds or only the Ease and the other respective parameter will be added automatically from the default value.
If set to true, it will automatically apply the default value.
If set to false, there will be no animation effect.
For all of the available easing values, see the Easing options at the bottom of the table.
imageTextHide false
true
false
If the image overlay text should be hidden by default and shown when mousing over the stage.
imageTextBackground "gradient"
"gradient"
"plain"
The background type of the image text, either "gradient" or "plain".
Applicable when the images have texts.
imageTextAnimate [250, "easeOutQuad"]
[Milliseconds, Ease]
Milliseconds
Ease
true
false
The animation parameters of the image text.
The normal value is an array containing the duration of the animation, in milliseconds, and the animation ease: [250, "easeOutQuad"].
It is possible to specify only the Milliseconds or only the Ease and the other respective parameter will be added automatically from the default value.
If set to true, it will automatically apply the default value.
If set to false, there will be no animation effect.
For all of the available easing values, see the Easing options at the bottom of the table.
Applicable when imageTextHide is set to true.
imageTextsEnabled true
true
false
If the image texts should be enabled and displayed.
This is a useful option to have when customizing the gallery to be able to switch easily between displaying image texts and not, without needing to modify any HTML code.
navArrows true
true
false
If the stage should have left and right navigation arrows.
closeButton true
true
false
If the stage should have a close button.
controlsHide false
true
false
If the stage controls (nav arrows and close button) should be hidden by default and show when mousing over the stage.
controlsAnimate [250, "easeOutQuad"]
[Milliseconds, Ease]
Milliseconds
Ease
true
false
The animation parameters of the stage controls.
The normal value is an array containing the duration of the animation, in milliseconds, and the animation ease: [250, "easeOutQuad"].
It is possible to specify only the Milliseconds or only the Ease and the other respective parameter will be added automatically from the default value.
If set to true, it will automatically apply the default value.
If set to false, there will be no animation effect.
For all of the available easing values, see the Easing options at the bottom of the table.
Applicable when controlsHide is set to true.
// Other
textColor "black"
"black"
"white"
The color of the gallery text that is displaying directly over the page background. Currently, this applies to the title and the subtitle.
This is an easy and fast way to switch the text color to white when the page background is dark.
borders false
"small"
"big"
false
If there should be and the type of borders around the thumbs and the stage.
They can be "small" (1px) or "big" (2px). To have no borders, set to false.
wideBackground false
"all"
"body"
"stage"
true
false
If the gallery should have a background that extends as wide as the container target of the gallery (parent or window).
The background can be applied to "all" the gallery, to the "body" or only to the "stage".
If set to true it will default to "body" and if set to false, it will be disabled.
wideBackgroundTarget "parent"
"parent"
"window"
If the wide background should be applied based on the parent element of the gallery or based on the browser window.
Applicable when wideBackground is set to true.
// Scroll
scrollToImage true
true
false
If the page should automatically scroll to the opened image if it is out of view.
scrollAnimate [500, "easeOutQuad"]
[Milliseconds, Ease]
Milliseconds
Ease
true
false
The animation parameters of the automatic scrolling.
The normal value is an array containing the duration of the animation, in milliseconds, and the animation ease: [500, "easeOutQuad"].
It is possible to specify only the Milliseconds or only the Ease and the other respective parameter will be added automatically from the default value.
If set to true, it will automatically apply the default value.
If set to false, there will be no animation effect.
For all of the available easing values, see the Easing options at the bottom of the table.
Applicable when scrollToImage is set to true.
// Global
defaultOpen 1
Number
false
The number of the image opened by default.
If set to false or to 0, then no image will be opened by default.
font "default"
"default"
"page"
What font should the gallery use, its own default font or the one from the page it is on.
loop true
true
false
If the gallery should loop from the last image to the first (and vice-versa) or from the last row to the first (and vice-versa) when navigating using the arrow buttons or the keyboard arrows.
keyboardArrows "all"
"all"
"left-right"
true
false
What keyboard arrows should be available for navigation.
If set to "all" then all arrows - left, right, up and down - can be used, if set to "left-right" then only the left and right arrows are available.
If set to true, it will default to "all", if set to false, then navigation by keyboard arrows will be disabled.
The arrows can be used to navigate when at least a small portion of the gallery is in view on the page.
responsive true
true
false
If the gallery should be responsive and resize automatically based on the available space.
Easing options:

The available easing 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

CSS and JS code

CSS code

You can edit the CSS code to customize anything about the gallery look that you want. The gallery CSS file is named sharp-gallery.css and you can find it in the sharp-gallery/css folder. Open this file in a text editor and you have access to customize all of the gallery styles.

You will need to be familiar with how CSS works in order to make any customizations in the code here but, fortunately, it is not that hard to pick up and learn the basics of how CSS works.

The code is ordered to resemble the structure of the gallery HTML code, to make it easier to understand and work with. Comments are at the head of every section and the styles inside are about elements in that section.

You can play around and experiment with customizing the CSS code in different ways. Don't be afraid of breaking anything because you always have the original file as a backup, in case anything goes wrong.

JavaScript code

For more advanced users, it is also possible to edit the JavaScript code in order to customize anything about the gallery functionality that you want. The JS file included with the gallery files is called jquery.sharp-gallery.min.js and is found in the sharp-gallery/js folder. But this is the minified (compressed) version. What you need is the uncompressed source version that you can find in the Source/js folder and is called jquery.sharp-gallery.js.

When you want to make changes to the JS code, you can delete the old compressed file, copy this source version and paste it in the sharp-gallery/js folder, and rename it to add the .min at the end. Now the gallery is loading and using the uncompressed version to which you can make changes and see the changes live.

After you open this file in a text editor, you can see and edit the uncompressed gallery JavaScript code. You will need to be familiar with JS in order to make any changes here but don't be afraid to experiment as you will always have the original version available as a backup.

The bulk of the code is in the build function, where the gallery is initialized and its functionality built.

After you have made the changes that you want, it is a good idea to compress the file in order to make it a smaller size and decrease the loading time on the user end. But before doing that, remember to save an uncompressed copy for yourself, in case you need it later.

To compress a JS file, you can use the free and very good tool at jscompress.com. That is the same tool I used. Simply copy all of the code from the file and paste it there and after it is compressed, copy the code back to your file. Now the JS file is compressed and ready to go.

Problem! What do I do?

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

  • Make sure that you have transfered all of the gallery code.
  • Make sure that all of the needed files are accessible and loading well (CSS, JS, images).
  • Make sure that jQuery is not added multiple times on the page.
  • Look in the browser console to see if any error message is shown.
  • Have a look over the Install and Customize sections to make sure you have done everything right.

If you cannot fix the problem, please 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 page so that I can see and investigate the problem directly. 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 [email hidden in preview].

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.

Below are links to some resources that you might find useful when working with the gallery:

Credits

Thank you to the following: