• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • About
  • Projects
    • GStaticMap WP Plugin
  • Contact
  • Privacy Policy

Lorenz Blog

All About Web & Mobile Application Development

  • Featured Articles
  • Gadgets
    • Android
    • Blackberry
  • Programming
    • Android
    • PHP
    • Java Script
    • MySQL
    • Postgresql
    • Flex
    • Web
  • Software
    • Mac OS
    • Windows
    • Linux
  • Web
You are Here » Home >> Information Technology >> Programming >> Java Script >> How to Create Scrollable Image Slider Using JavaScript

How to Create Scrollable Image Slider Using JavaScript

January 23, 2010 by Lorensius Londa 21 Comments

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
  • <script src="scripts/jquery.tools.min.js" type="text/javascript"></script>
    

    or

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

Using Scrollable UI library

HTML Code

<a class="prevPage left"></a>
<div class="scrollable">
    <div class="items">
        <!-- 1-4 -->
        <img src="http://londatiga.net/tutorials/scrollable/images/img1.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img2.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img3.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img4.jpg" />

        <!-- 5-8 -->
        <img src="http://londatiga.net/tutorials/scrollable/images/img5.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img6.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img7.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img8.jpg" />

        <!-- 10-12 -->
        <img src="http://londatiga.net/tutorials/scrollable/images/img9.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img10.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img11.jpg" />
        <img src="http://londatiga.net/tutorials/scrollable/images/img12.jpg" />
    </div>
</div>

<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

.scrollable {
	background: #ccc;
	position: relative;
	overflow: hidden;
	width: 690px;
	height:145px;
	border:1px solid #ccc;
	-moz-border-radius:4px;
	-webkit-border-radius:4px;
}

.scrollable .items {
	width: 20000em;
	position: absolute;
	clear: both;
}

.scrollable img {
    opacity: 0.6;
	float:left;
	margin:15px 5px 15px 15px;
	background-color:#fff;
	cursor:pointer;
	width:150px;
	height:113px;
	-moz-border-radius:4px;
	-webkit-border-radius:4px;
}

.scrollable .active {
    opacity:1;
	border:2px solid #000;
	z-index:9999;
	position:relative;
}

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)

.scrollable { float:left; }

a.left, a.right {
	display: block;
	width: 18px;
	height: 18px;
	float: left;
	margin: 60px 10px;
	cursor: pointer;
}

a.right { background: url(scrollable/arrow/right.png) no-repeat;  clear:right; margin-right: 0px;}
a.right:hover  { background-position:0px -18px; }
a.right:active 	{ background-position:0px 0px; }

a.left	{ background: url(scrollable/arrow/left.png) no-repeat;  margin-left: 0px; }
a.left:hover  { background-position:0px -18px; }
a.left:active  { background-position:-0px 0px; }

a.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

<script>
	$(function()  { $("div.scrollable").scrollable({size: 4}); });
</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 Demo | Download Example Source Code
Facebooktwitterredditpinterestlinkedinmailby feather

Related posts:

  1. How to Overlay Video Using JQuery Tools and Flowplayer
  2. How to Crop Image Using JavaScript and PHP
  3. How to Create Image Overlay Using Javascript
  4. How to Create Flash Like Image Slideshow with JavaScript

Filed Under: Featured Articles, Java Script, PHP, Programming Tagged With: image slider, javascript, jquery, scrollable, scrollable image gallery, scrollable images, scrolling image, tools, user interface

About Lorensius Londa

Passionate web and mobile application developer. Co-founder of TRUSTUDIO, loves programming, Android, aviation, travelling, photography, coffee and gym mania.

Reader Interactions

Comments

  1. JavascriptBank.com says

    January 24, 2010 at 9:21 am

    very cool & good tip, thank you very much for sharing.

    Can I share this post on my JavaScript library?

    Awaiting your response. Thank

    Reply
    • lorenz says

      January 26, 2010 at 5:38 pm

      yes, please..

      Reply
  2. Selby says

    March 13, 2010 at 1:55 am

    I very enjoy this fantastic post which are provided for us. I confirm this would be advantageous for most of the people.

    Reply
  3. cre8tvnrg says

    October 21, 2010 at 1:45 am

    I am looking for a scrollable gallery like this (Non-Flash) that shows all thumbnail images black and white – then when you roll over a thumbnail image it becomes full color AND populates in a full size larger cell above the gallery scroll bar, is this possible? If so, how would this be accomplished?
    Please advise?

    Reply
  4. ghd straightener says

    October 22, 2010 at 4:40 pm

    I’ve been looking for something like this! Thanks for sharing this great tool!

    Reply
  5. ghd straightener says

    October 22, 2010 at 4:41 pm

    it makes you wonder where people get the idea that short-term planning will yield immediate rewards.

    Reply
  6. Johnathan says

    October 22, 2010 at 6:41 pm

    Thank you so much for this tutorial! This will surly! I can now finish my website off for a college assignment!

    Reply
  7. Johnathan says

    October 22, 2010 at 6:42 pm

    Thank you so much for this tutorial! This will surly help me finish my website off for a college assignment!*

    God knows what I typed before…

    Reply
  8. guitarcal says

    November 23, 2011 at 3:20 am

    How would you modify this to display information text when each picture is clicked on a different portion on your website?

    Reply
  9. Pharmd604 says

    August 20, 2012 at 7:35 pm

    Hello! eegdagf interesting eegdagf site! I’m really like it! Very, very eegdagf good!

    Reply
  10. viagra says

    October 31, 2012 at 3:45 am

    Hello!
    , , , ,

    Reply
  11. Jamie says

    October 2, 2013 at 7:05 pm

    Hi I am new to JQuery what do I need to download before incorporating the code ?

    Reply
  12. Jamie says

    October 2, 2013 at 7:07 pm

    Also the links in set up section don’t work

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About Me

A husband, father of two, passionate software developer, diy lover and home baker who loves to learn new things. Read More…

  • Facebook
  • GitHub
  • Google+
  • Instagram
  • Twitter
  • YouTube

Featured Articles

How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Blue Bamboo P25 Printer Android Demo Application With Source Code

Simple JSON RPC Client for Android

How to Send Message to Google Cloud Messaging (GCM) Server Using JSON and PHP

Footer

Recent Comments

  • Aditya Dabas on About
  • Ayten Göksenin Barutçu on How to Make Android Map Scrollable Inside a ScrollView Layout
  • mang jojot on About
  • Hussain on How to Programmatically Scan or Discover Android Bluetooth Devices

Recent Posts

  • How to Fix Blank Screen on WordPress Add/Edit Post Page
  • How to Programmatically Restart the ESP32 Board
  • How to Get Hardware Info of ESP32
  • How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Latest Tweets

  • @tricahyono_bowo @infobandung @infobdg Wah kejauhan om 310 days ago
  • Wilujeng enjing sadayana..Mohon info tempat powder coating dan sandblasting yg recommended di Bandung dunk @infobandung @infobdg314 days ago

Copyright © 2023 · Magazine Pro on Genesis Framework · WordPress · Log in