Thickbox add previous and next button on image like Lightbox

by jinweijie on January 1, 2011

Lightbox has a fancy effect that use can navigate image back and forth by clicking the left or the right side of the current image. This is nice for the Thickbox being used in NextGen Gallery which is a gallery plugin for wordpress.

I modified the Thickbox jQuery plugin  to implement the same thing.

First, let’s check out the result which we’re going to accomplish. Visit one of my photo album, for example: http://www.jinweijie.com/photo/?album=1&gallery=3 , clicking one of the image, after its loading, the image can be clicked to view the previous or the next one depending the side you clicking:

image

And there will be an arrow shown when your mouse move on the image to show the next or the previous.

Also, my modification includes preloading next two images.

Now let’s see the code:

1. First, you need three images: left.gif, right.gif, pixel.gif. They are enclosed in the zip file which you can download at the bottom.

2. Modify the thickbox.css, add the following code at the end of the file:

#divNavControl{
    position: absolute;
    z-index:999;
}

#divPre{
     height: 100%;
    left: 0;
    position: absolute;
    width: 50%;
    background:url(pixel.gif) repeat;
    cursor:pointer;
}

#divNext{
    height: 100%;
    position: absolute;
    right: 0;
    width: 50%;
    background-color:transparent;
    background:url(pixel.gif) repeat;
    cursor:pointer;
}

#imgLeftArrow{
    position:absolute;
    top:45%;
    left:0;
}

#imgRightArrow{
    position:absolute;
    top:45%;
    right:0;
}

3. Modify the thickbox.js, add the image variable at the top of the file:

if ( typeof tb_leftArrow != 'string' ) {
    var tb_leftArrow = "../wp-includes/js/thickbox/left.gif";
}

if ( typeof tb_rightArrow != 'string' ) {
    var tb_rightArrow = "../wp-includes/js/thickbox/right.gif";

Then modify the tb_show function, the code is too long so I zipped them, please Download the zip file.

Click here to download the modified Thickbox package for WordPress.

Click here to download standalone version.

Any question, please comment below, enjoy! Smile

{ 12 comments… read them below or add one }

Peter April 1, 2011 at 6:33 am

I’m trying to add navigation to the pop-up windows and will try your advice.
How do you modify the tb_show function?
Thanks
Pete

jinweijie April 10, 2011 at 4:12 pm

hello, what do you mean by how?

ruchi May 6, 2011 at 8:04 pm

hi jin,
its a pleasure to knw you… well just goolgling for some thickbox related queries i found ur profile.
i am having one problem, could you plz hve luk and reply me as soon as possible…
if you got to this link..
http://jquery.com/demo/thickbox/
in example theres a image gallery example like that only .. rather then image i want to show div contents in “next” and “previous” click .
i hope you understand the peoblem…

well i am able to show the pop up window and starting with the div which i want to show first (this is done just reffering the example for inline content in thickbox link)and when i click on the next or previous button i want to remove that div and want to show contents of another… div…

so could you please tell me … what should be the code for next and previous button…

hope to hear from you soon…

regards
ruchi

Michael July 7, 2011 at 10:02 pm

Hi,

great work. It was very annoying when the slides closes by clicking one millimeter beside the next or prev link. You have to start with the first image once again. But this is now history

Many, many Thanx,
Michael.

Marcos July 27, 2011 at 4:56 am

Hello. I didn’t get this to work and I have a feeling its because of the way I linked my images to open with thickbox. I added this code:

[code]

jQuery(document).ready(function() {
jQuery(".entry-content a img").parent("a[href*=layback]").addClass("thickbox");
});

[/code]

To my single.php file. This way, all the images in a post open up on thickbox. But I never got a caption on the thickbox window, and after the modified files you posted here, its still the same. just the one image, with a X ……………button on the bottom right corner. Any help is appreciated! Thanks.

Gregg July 29, 2011 at 1:25 am

Hi, First off, great tut, works awesome on my site. I was wondering if you know a way to include the image alt /title as well as the description. So show the image name, and if there is a description (+caption+), show that as well. That way, some text will always show, even if it is something so bland as ‘image064′. Thanks!

jinweijie July 29, 2011 at 9:34 am

I think you need to modify the upload module of the image.

Lou January 9, 2012 at 3:25 am

Awesome work jinweije! This is just what i was looking for.

I’m now trying to make thick box go to the last image when clicking on the left portion of the first one, and go to the first one when cliking on the right part of the last one. Any help nor clue would be apreciated.

jinweijie January 10, 2012 at 9:37 am

Hi Lou,

I think you can modify the function tb_show(caption, url, imageGroup) function in the thickbox.js file

Ainsley February 13, 2012 at 10:29 pm

Awesome stuff man!

Makes it a lot easier to navigate through my pics.
Thank you.

Ains

jinweijie February 13, 2012 at 11:01 pm

glad to hear that. :)

jinweijie February 13, 2012 at 11:03 pm

checked out your site, great illustrations! i like them.

Leave a Comment

Previous post:

Next post: