Thumbnail Slider
Features
- Supports responsive layout
- Tap or swipe navigation on touch-enabled devices
- Horizontal or vertical orientation
HTML
<div id="thumbnail-slider">
<div class="inner">
<ul>
<li><a class="thumb" href="img/1.jpg"></a></li>
<li><a class="thumb" href="img/2.jpg"></a></li>
<li>
<a href="/"><img class="thumb" src="1.jpg" style="height:auto;" /></a>
</li>
</ul>
</div>
</div>
Alternative markup
The thumbnail images are typically defined using the following format:<a class="thumb" href="1.jpg"></a>
The script thumbnail-slider.js will set a background image based on the href value.
Benefits of this format:- supports lazy loading of images
-
When thumbnails have different aspect ratios, it is easier to cutomize their appearance with CSS:
.thumb { background-size:contain; /*or: cover*/ }
Alternative Markup
In some cases, you may prefer or need to use a different markup structure for thumbnails.
For example, if a thumbnail must be wrapped inside a link, you cannot use the format above, since nested anchor tags are invalid in HTML.
Alternative examples:
<a href="/"><span class="thumb" style="background-image:url(1.jpg)"></span></a>
or:
<a href="/"><img class="thumb" src="1.jpg" /></a>
or:
Any HTML content. Each slide (<li>) can contain any type of HTML, even plain text without an image.
JavaScript
Open the thumbnail-slider.js in the download package and configure the options as needed:
var thumbnailSliderOptions = {
sliderId: "thumbnail-slider",
orientation: "horizontal", // or "vertical"
thumbWidth: "140px", // or "xx%", or "auto"
thumbHeight: "70px", // or "xx%", or "auto"
showMode: 1,
autoAdvance: true,
selectable: true,
slideInterval: 3000, // in ms
transitionSpeed: 300, //The roll-in duration in ms
shuffle: false,
startSlideIndex: 0, // The index of the slide to start from (0-based).
pauseOnHover: true,
initSliderByCallingInitFunc: false,
rightGap: 0, // or 90, or "default"
keyboardNav: true,
mousewheelNav: false,
before: null,
};
var mcThumbnailSlider = new ThumbnailSlider(thumbnailSliderOptions);
- 1: Move one by one; rewinds to the start after the last thumbnail.
- 2: Highlight one by one; scrolls only when the active thumbnail is out of view; rewinds at the end.
- 3: Highlight one by one. active thumbnail stays centered; loops continuously.
- 4: Scrolls a full group of visible thumbnails at a time; rewinds after the last group.
- The current active thumbnail receives the CSS class active, allowing it to appear differently from others.
- Clicking a thumbnail updates the current active index and sets that thumbnail as active.
Note: When showMode is 2 or 3, this is automatically overridden to true.
In thumbnail-slider.js you will find the following line of code:
var mcThumbnailSlider = new ThumbnailSlider(thumbnailSliderOptions);
This line initializes the slider when the page loads.
If the slider markup is not available, or it is (or its container is) display: none, the slider should not be initialized during page load. Instead, the slider should be initialized using one of the two methods below after the markup is ready or the container becomes visible.
-
Option 1: Set initSliderByCallingInitFunc: true
When this option is enabled, the slider will not be instantiated automatically.
You will need to explicitly call the initialization function when ready:mcThumbnailSlider.init(); -
Option 2: Manually instantiate the slider
Remove the following line from the thumbnail-slider.js:
var mcThumbnailSlider = new ThumbnailSlider(thumbnailSliderOptions);Then, add the line to the location in your code where the slider should be initialized (i.e., when the markup is ready or the container becomes visible).
Note: the option initSliderByCallingInitFunc must be set to false when using this approach.
An integer or "default" that specifies the empty space between the last thumbnail and the slider's right border (or bottom border if orientation: "vertical").
If showMode is not 3, the last thumbnail may leave a blank area when scrolled into view.
Examples:- {rightGap: "default"} — keeps the default blank space.
- {rightGap: 0} — removes any blank space after the last thumbnail.
- {rightGap: 100} — allows up to 100px of blank space after the last thumbnail.
See the flickr-like-slideshow for an example of using this callback to synchronize with another slider.
Built-in Functions
If you need to control the slider programmatically, click here for more details.
Styles
The styles are primarily configured in the thumbnail-slider.css file.
However, note that some styles are defined in the thumbnail-slider.js script, such as orientation, thumbWidth, thumbHeight, and rightGap, as mentioned in the JavaScript section above.