Easily and effectively display images with FancyBox

by Wez on August 29, 2009

fancybox Easily and effectively display images with FancyBoxFancyBox is a plugin for jQuery that allows you to easily display images in the same window with a simple yet effective code. The plugin takes no time to set up and all that is required is that you include the jQuery javascript library within the pages that you are using the FancyBox plugin on.

Features:

  • Display single images
  • Create image galleries
  • Display iFrame
  • Execute Ajax
  • Include Flash, movies or audio files

Using FancyBox

First of all we need to link to the jQuery and FancyBox file after we have downloaded.

<script type="text/javascript" src="path-to-file/jquery.js"></script>
<script type="text/javascript" src="path-to-file/jquery.fancybox.js"></script>


Next we add the stylesheet that is included with FancyBox:

<link rel="stylesheet" href="path-to-file/fancybox.css" type="text/css" media="screen">

Then to link to an image we simply set the id of an image to "single_image":

<a id="single_image" href="image_big.jpg"><img src="image_small.jpg" alt=""/></a>

All that is left to do is execute the jQuery code when the DOM is loaded.

$(document).ready(function() {
 
    $("a#single_image").fancybox();
 
}

That is all the code that is needed to display a single image. To learn how to do things such as ajax calls, view the documentation for FancyBox here.

Other lightbox alternatives

Is there another lightbox alternative that you have used that you would like to share with all the readers? Post a comment below.

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • FriendFeed
  • LinkedIn
  • Ping.fm
  • Tumblr
  • Twitter

Related posts:

  1. Quick Tip: Resolving conflicting problems between jQuery and MooTools or any other Javascript library Recently I wrote quite a huge chunk of jQuery for...
  2. ASCIICasts: AJAX History and Bookmarks View full tutorial In the last episode we added AJAX...
  3. 10 CakePHP Tutorials You Should Read There are a number of frameworks available for PHP such...
  4. jQuery #1 Learn how to use the animate function within the jQuery...
  5. Best Websites For Ruby On Rails Examples and Tutorials Ruby on Rails is a framework for Ruby that has...

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Comment

Previous post: PHP Contact Form

Next post: Send form data to PHP without the whole page reloading using jQuery