Create Sliding Photo Gallery using jQuery

Free photo gallery is one of the interesting features in the world of web.

This free HTML JavaScript tutorial don't guide you create a flash sliding gallery, but sliding image gallery; by using jQuery scrollable UI library.

Please go to the detailed post to get full instructions and JavaScript example codes for a beautiful web photo gallery on your website.


Sampled by © JavaScriptBank.com

Scrollable image slider  is one of the interesting features in the image gallery application. This allows us to display thumbnails in the form of slides that can be scrolled automatically or manually using the control buttons.

Figure below shows a scrollable image slider featuring four thumbnails per slide. To display thumbnails from another slide, simply by clicking the navigation buttons located on the right and left slide. Slides can also be scrolled automatically by using the  left and right arrow keyboard or using  the mouse wheel.

Scrollable image gallery

Scrollable image slider

In this tutorial, i'll use Scrollable component from jQuery Tools user interface (UI) library which is based on popular jQuery javascript framework. Current version of jQuery Tools at the time of this writing is version 1.1.2, which can be downloaded here. The library itself consists of six user interface components that can be easily combined:  Tabs, Tooltip, Overlay, Scrollable, Expose, and Flashembed.

How to Setup

  • Download Scrollable component from download page and save it as jquery.tools.min.js. You can download it with jQuery (v1.3.2)  as a single file (21.75 kb) or as a separated file (3.37 kb) if you already have jQuery.
  • Include the jquery.tools.min.js in the HEAD section of your HTML file
  • 1<script src="scripts/jquery.tools.min.js" type="text/javascript"></script>

    or

    1<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    2<script src="scripts/jquery.tools.min.js" type="text/javascript"></script>

Using Scrollable UI library

HTML Code

01<a class="prevPage left"></a>
02<div class="scrollable">
03    <div class="items">
04        <!-- 1-4 -->
09 
10        <!-- 5-8 -->
15 
16        <!-- 10-12 -->
21    </div>
22</div>
23 
24<a class="nextPage right"></a>

line 01:  element for left/prev  button.

line 02: root element (div) for the scrollable.

line 03: wrapper element.

line 04-20: scrollable images (will be displayed  four images per slide).

line 24: element for right/next button.

CSS Code

Scrollable

01.scrollable {
02    background: #ccc;
03    position: relative;
04    overflow: hidden;
05    width: 690px;
06    height:145px;
07    border:1px solid #ccc;
08    -moz-border-radius:4px;
09    -webkit-border-radius:4px;
10}
11 
12.scrollable .items {
13    width: 20000em;
14    position: absolute;
15    clear: both;
16}
17 
18.scrollable img {
19    opacity: 0.6;
20    float:left;
21    margin:15px 5px 15px 15px;
22    background-color:#fff;
23    cursor:pointer;
24    width:150px;
25    height:113px;
26    -moz-border-radius:4px;
27    -webkit-border-radius:4px;
28}
29 
30.scrollable .active {
31    opacity:1;
32    border:2px solid #000;
33    z-index:9999;
34    position:relative;
35}

line 01, style for  container element, the length and width depends on image size and how many images you want displayed per slide.

line 12, style for wrapper element.

line 18,  style for images in a slide.

line 30, style for selected image.

Navigation button (prev & next)

01.scrollable { float:left; }
02 
03a.left, a.right {
04    display: block;
05    width: 18px;
06    height: 18px;
07    float: left;
08    margin: 60px 10px;
09    cursor: pointer;
10}
11 
12a.right { background: url(scrollable/arrow/right.png) no-repeatclear:right; margin-right: 0px;}
13a.right:hover  { background-position:0px -18px; }
14a.right:active  { background-position:0px 0px; }
15 
16a.left  { background: url(scrollable/arrow/left.png) no-repeatmargin-left: 0px; }
17a.left:hover  { background-position:0px -18px; }
18a.left:active  { background-position:-0px 0px; }
19 
20a.disabled { visibility:hidden !important; }

line 01, allow next and  prev buttons placed on each side of the slide.

line 12,  set size and position of prev and next buttons.

line 16,  set background image for prev and next buttons.

Javascript Code

1<script>
2    $(function()  { $("div.scrollable").scrollable({size: 4}); });
3</script>

$("div.scrollable") is a jQuery selector for scrollabe container. On example above, we set four images for each slide using configuration parameter 'size'. Default value of 'size' parameter is 5. You can learn more about the API of the Scrollable component on this page.

View Live DemoDownload Example Source Code

Language
Translate this page to English Translate this page to French Translate this page to Vietnamese

Recent articles
Insights for Advanced Zooming and Panning in JavaScript Charts
How to open a car sharing service
Vue developer as a vital part of every software team
Vue.js developers: hire them, use them and get ahead of the competition
3 Reasons Why Java is so Popular
Migrate to Angular: why and how you should do it
The Possible Working Methods of Python Ideology
JavaScript Research Paper: 6 Writing Tips to Craft a Masterpiece
Learning How to Make Use of New Marketing Trends
5 Important Elements of an E-commerce Website


Top view articles
Adding JavaScript to WordPress Effectively with JavaScript Localization feature
Top 10 Beautiful Christmas Countdown Timers
Top 10 Best JavaScript eBooks that Beginners should Learn
65 Free JavaScript Photo Gallery Solutions
16 Free Code Syntax Highlighters by Javascript For Better Programming
Best Free Linux Web Programming Editors
Top 50 Most Addictive and Popular Facebook mini games
More 30 Excellent JavaScript/AJAX based Photo Galleries to Boost your Sites
Top 10 Free Web Chat box Plug-ins and Add-ons
The Ultimate JavaScript Tutorial in Web Design


Free JavaScript Tutorials & Articles
at www.JavaScriptBank.com