Gambit Torchbox Lightbox Javascript Demo & Instructions

Our Torchbox lightbox script is our take on a fast, easy to use and minimalist lightbox. Unlike the rest, this is a pure Javascript implementation and is more or less a drop-in lightbox solution with minimal setup required.

When a Torchbox image is clicked, it will open it inside a lightbox. It would look like your image pops out of its place and gets enlarged to full view. Awesome.

The image caption get displayed when the lightbox finishes its animation. The high resolution version (if provided) will load and will replace the image in the lightbox when it's ready. And if the script detects that there are other Torchboxes, it will display a previous and next arrow inside the lightbox so that your visitors can switch back and forth between images.

Try it out below!

See it in Action

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet felis mattis, mollis tellus quis, efficitur orci. Ut diam odio, bibendum sit amet lectus quis, tempor euismod lectus. Fusce ac ligula nulla. Vestibulum congue lorem quis magna rhoncus mattis. Integer non convallis magna, vitae accumsan mauris. Proin varius risus a erat commodo commodo. In eu leo id eros dignissim accumsan sit amet non urna. Morbi molestie, mi ac maximus rutrum, ipsum lorem ultrices turpis, dapibus rutrum ex neque vitae nunc. Proin ut consectetur dui. Morbi aliquam purus sem. Duis quis risus quis nulla ultrices aliquam ut eu mi. Aliquam dictum vel urna id fringilla. In hac habitasse platea dictumst. Vivamus pulvinar felis et sodales efficitur. Curabitur viverra, mauris sit amet feugiat varius, erat purus interdum urna, ut ornare libero lorem vel risus.

Aliquam tincidunt nisl vel metus laoreet facilisis. Maecenas finibus est eget orci rutrum, a porta elit vehicula. Pellentesque urna elit, eleifend aliquet sapien eu, fermentum malesuada mi. Vivamus facilisis, justo id mollis cursus, lacus augue lobortis erat, ac fringilla nisi ipsum quis elit. Fusce cursus ligula sed ornare euismod. Sed est neque, pharetra elementum tristique a, elementum sed dolor. Etiam accumsan molestie bibendum.

Maecenas scelerisque eros orci, vehicula suscipit urna varius ut. Integer neque elit, faucibus eget lorem et, imperdiet tempus mi. Curabitur semper tempor tellus, id tristique velit viverra ac. Vivamus vel congue est. Pellentesque luctus aliquam lectus non auctor. Quisque consequat mi nec risus tempor euismod. Vestibulum rutrum sapien quis lectus sagittis aliquam. Quisque blandit nisl non fermentum aliquam. Mauris vestibulum lectus lectus, sed aliquam nunc laoreet non. Quisque sed sapien ultricies, sodales augue non, hendrerit enim. Proin ultrices sed augue vel auctor. In volutpat urna ac purus tempor, ut consequat massa lobortis. Curabitur tempor sit amet sem mollis vulputate. Curabitur in scelerisque leo.

Vestibulum a mi magna. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean non massa in nisl sagittis porttitor. Praesent tempus, lectus ac tempor auctor, massa turpis vehicula lorem, vitae suscipit odio lacus vel ex. In sed elementum risus. In vulputate orci et eleifend volutpat. Maecenas tempor, dolor sed blandit viverra, arcu sapien tristique tortor, commodo rutrum ante ipsum id magna. Quisque vel volutpat mauris. Curabitur vestibulum tincidunt consequat. Duis faucibus diam at justo fermentum, nec tempus est porttitor.



One. به قالب خود اضافه کنید

کپی کنید اسکریپت و به قالب خود قبل از تگ <head>

<script type='text/javascript' src=''></script>
<link href='' rel='stylesheet' type='text/css'>

Two. مقدار دهی اولیه

Start Torchbox with this line of code, put this in your <head> tag.

var torchbox = new GambitTorchbox();
Do not wrap this initialize code inside jQuery's ready function or a document onload listener.

Three. این کلاس ها و اتریبیوت ها را به عکس های خود اضافه کنید

You'll need to add a class & a few attributes to your image tags in order to make them trigger a Torchbox when clicked.

Modify your <img> tags:

  1. به عکس های خود این کلاس را بدهید gambit_torchbox,
  2. هم چنین این اتریبیوت را data-hires و در اون آدرس عکسی که می خواید توی لایت باکس نمایش داده بشه رو بذارید
  3. Add a title attribute and put in the caption that you want to show up with the image.
If the data-hires is not present, the high resolution image will not be loaded, and your torchbox will show the same image instead. If the title attribute is not present, no caption will be displayed. TIP: If you don't want to add classes, you can change the selector setting (see Settings section below).

Setup Example

For example, if you have this in your HTML and you want this to have a Torchbox:

<img src=''/>
You should end up with:
<img src='' class='gambit_torchbox' data-hires='' title='This is a cool image'>
In this example, the low resolution image is and
the high resolution image is


When initializing Torchbox, you can provide some settings if you want to change the default behavior. Here is how you can do it and the default parameters:

var torchbox = new GambitTorchbox({
	// The selector to use to search for images to attach lightboxes to
	'selector': '.gambit_torchbox',
	// The name of the attribute that carries the URL to the high resolution image to display.
	'highres_attribute': 'data-hires',
	// The name of the attribute that caption of the image.
	'caption_attribute': 'title',
	// If true, arrows will be displayed for navigating to the previous/next Torchbox image
	'navigation': true,
	// If true, keyboard navigation (left, right & escape to close) will be enabled
	'key_navigation': true,
	// Lightboxes are disabled for mobile devices, choose whether images should open as links or do nothing
	'mobile_behavior': 'none', // 'none' or 'open',
	// The width to determine if we are in a mobile device
	'mobile_width': 800

متدها و عملگرها

شما می تونید با این عملگرها لایت باکس رو کنترل کنید

I'm assuming here that you have the instance of GambitTorchbox in a variable torchbox

Open a lightbox

// Open the lightbox of the image with an id of `foo`
var el = document.querySelector('#foo'); el );

Close the current lightbox


With a Torchbox open, move to the next image;

With a Torchbox open, move to the previous image


Refresh the position of the Torchbox (to ensure it's in the middle of the screen)


تغییر استایل لایت باکس

All the styles can be adjusted in CSS. We have provided SCSS files for each component of Torchbox so you can edit them individually.

For reference, here are a few CSS examples on adjusting the major components of Torchbox and their default values:

Overlay color & opacity

.gambit_torchbox_bg {
	background: #000;
} {
	opacity: .85;

Caption color

.gambit_torchbox_caption {
	color: #fff;

Caption gradient background tint

.gambit_torchbox_caption:before {
	background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.55) 100%);

Loading icon color > div {
	color: #fff;
	background: #fff;
	border-color: #fff;

Arrow button background & hover opacity

.gambit_torchbox_prev, .gambit_torchbox_next {
	background: rgba(0,0,0,.5);
}, {
	background: rgba(0,0,0,.8);

Arrow button arrow color

.gambit_torchbox_prev:before, .gambit_torchbox_prev:after,
.gambit_torchbox_next:before, .gambit_torchbox_next:after {
	background: #fff;