Demos:
Installation
Step 1
First, you have to include the JQuery library between the <head> and </head> tags of your html page:
<script type="text/javascript" src="jquery-latest.pack.js"></script>
Step 2
Once you inclued JQuery to your html file, you have to include the following functions. To do so, embed it within <script type=”text/javascript”> //the code here </script>, or even better, put it in a separate .js file.
this.screenshotPreview = function(){
/* CONFIG */
xOffset = 10;
yOffset = 30;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("a.screenshot").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "
" + this.t : "";
$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");
$("#screenshot")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#screenshot").remove();
});
$("a.screenshot").mousemove(function(e){
$("#screenshot")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
this.imagePreview = function(){
/* CONFIG */
xOffset = 10;
yOffset = 30;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("a.preview").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "
" + this.t : "";
$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#preview").remove();
});
$("a.preview").mousemove(function(e){
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
this.tooltip = function(){
/* CONFIG */
xOffset = 10;
yOffset = 20;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("a.tooltip").hover(function(e){
this.t = this.title;
this.title = "";
$("body").append("<p id='tooltip'>"+ this.t +"</p>");
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#tooltip").remove();
});
$("a.tooltip").mousemove(function(e){
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
Step 3
Once you inclued the gallery functions, you have to activate it. Like for the functions, you can embed it on your html page or put it in a separate .js file.
$(document).ready(function(){
tooltip();//active les tooltip simple
imagePreview();//active les tooltip image preview
screenshotPreview();//active les tooltip lien avec preview
});
Step 4
The gallery is now fully functionnal. Though, we had to use some css to style it.
Paste the following code in your css file:
#screenshot{
position:absolute;
border:1px solid #ccc;
background:#333;
padding:5px;
display:none;
color:#fff;
}
#preview{
position:absolute;
border:1px solid #ccc;
background:#333;
padding:5px;
display:none;
color:#fff;
}
#tooltip{
position:absolute;
border:1px solid #333;
background:#f7f5d1;
padding:2px 5px;
color:#333;
display:none;
}
Step 5
Your gallery is now ready to use. Here’s 3 ways to use it:
To create a classic, but cool tooltip on a link, you have to give the html element a tooltip class, as well as a title:
<a href="http://cssglobe.com" class="tooltip" title="Web Standards Magazine">Roll over for tooltip</a>
To create an very fancy image preview, you have to add the preview class to your html element:
<a href="image.jpg" class="preview" title="Great looking landscape">Roll over to preview</a>
To create an image preview with a link to the full size image, you have to add the screenshot class to your html element, and a rel attribute, containing the full size image url as a value:
<a href="http://www.cssglobe.com" class="screenshot" rel="cssg_screenshot.jpg" title="Web Standards Magazine"> Css Globe</a>
This article is a translation from the French blog WebInventif.





My name is Jean-Baptiste Jung and I'm the man behind Cats Who Code. I started to use the Internet back in 1998 and started to create websites three years laters in 2001.
31 Comments
This is a really handy little script. Jquery is a good choice for something like this because it is a relatively small download. Have you seen dom tool tip? http://www.mojavelinux.com/projects/domtooltip/
It’s similar and has a smaller download footprint, but if your site is already using JQuery, then this script here is perfect.
Wow this looks really awesome. I checked out the demos and it looks really neat. I’ve been using lightbox which allows on page load up when you click an image, but the previews functionality of this tool take the cake. Thanks for the step by step advice!
I really like the image tooltip with captions.. Could think of some ways to use that
Here is a silly question, would that work on Wordpress blogs? (from all I know it was made especially for blogs
Thank you,
Motti
Adding images to blog posts is an easy way to make the blog look better and also keep people longer at your site.Thanks for the how-to tutorial!
Really good article! Thanks a lot
good tutorial!!!
thx!
Thanks for the tip. I’m happy with my current gallery though, so no switching at the moment.
Thanks for the great tutorial. I use jquery too, I get my code straight from their library. So this will add some great customization on my code.
Sweet – I’m not sure what use it would be of on my current blog, but if I ever make a personal blog that’s what I will use
Wow! thanks for the simple and quick tutorial. It would be very easy to follow.
I like JQuery very much and it was so well explained too. It’s very useful. Thanks
Thanks for this tutorial! Really helped alot..
I was not familiar with JQuery but it seems like a cool application. I will give it a try.
Great code man, much appreciated. Thanks for sharing
Thanks for the tutorial. Post made in right time for me, as i was just looking for fancy gallery customization. Got it installed and working perfectly.
nice work! I love the result.
Super, i love JQuery library and what you can do with it, this article is very helpful thank you ones more, i guess i have to bookmark your blog your doing excellent job!
Kind Regards,
Vasilis, UnitedWorx
Thanks for the awesome tip and code. jquery has grown big over the years. Recently I incorporated the jquery date picker into one of my self developed wordpress plugins. The styles are awesome…
Will try out this one
Wow these look great. I really like the link tooltip with preview!
I absolutely love jquery. It is amazingly easy to implement, even for someone with basic coding knowledge. It has become a life saver for sure.
That looks like Greek to me! Backend has never been quite my speciality, and things like this are best left to the professionals…..hahahaha, just kidding folks. We can all become experts eventually by heeding this and similar advise that is so generously served up by individuals like Jean-Baptiste!
Nice find Jean. It looks amazing and I’ll definitely give it a try, seems simple enough.
I didn’t know JQuery before. It seems to be a good program. Your tutorial is well explained too.
I have used this plugin for a project, but had broken his head slightly to get the image displayed on the left cursor hand.
Excellent script. And excellent step by step tutorial on how to use the script.
great coding and nice effort but the DEMO links work or i have a problem ?
Great article and well explained tutorial
I really liked the demo.
Excellent explanation with a nice demo.
I like demo easy for me but one problem ajax pagination without refresh inside div. It will not work with image pop. Any luck with script? Thanks.
Very intersting information. I think that I can use this on my site . Thanks !!!
11 Trackbacks
How to: Create a fancy image gallery with JQuery…
In this article, let’s have a look to some interesting script dedicated to create stunning tooltips and galleries with the help of Javascript….
[...] How to: Create a Fancy Image Gallery with jQuery [...]
[...] Como criar uma Galeria de Imagens com jQuery [...]
[...] [...]
[...] How to: Create a Fancy Image Gallery with jQuery [...]
[...] bağlantıların üzerine gelindiğinde, yazı veya resim görüntületebilirsiniz [...]
[...] How to: Create a Fancy Image Gallery with jQuery [...]
[...] How to: Create a Fancy Image Gallery with jQuery [...]
[...] How to: Create a Fancy Image Gallery with jQuery [...]
[...] How to: Create a Fancy Image Gallery with jQuery [...]
[...] How to: Create a Fancy Image Gallery with jQuery [...]