jQuery FaceBox Plugin

This code, as its names implies, creates a widget like the one widely used in the famous website facebook. It's far more efficient and nicer than a JavaScript alert() box. Any content can be loaded inside it, pretty helpful for user interaction as well. Source and © Chris Wanstrath.
  • Previous Resource
  • Download
  • Next Resource

Demonstration

FaceBox with remote content

Click here to open a remote page in a FaceBox

FaceBox with images

Click here to open an image in a FaceBox

FaceBox with hidden html

Click here to reveal an hidden div

How to setup

The first thing you'll have to do is to include the different files: the jQuery library, the plugin script and its style sheet.

  1. /** jQuery Inclusion **/
  2. <script type="text/javascript" src="Path_to/jQuery.js"></script>
  3. /** Plugin Inclusion **/</h3>
  4. <script type="text/javascript" src="Path_to/jquery-facebox.js"></script>
  5. /** Additional Style **/
  6. <link href="Path_to/facebox.css" rel="stylesheet" type="text/css"/>
  7. /** Plugin use **/

Then, you\'ll have to setup the facebox in the header or in a separate js file. The following code specifies that any link that has the rel attribute set to facebox will have the content of its href attribute displayed inside the facebox.

The fact to use the rel attribute is not compulsory, it is possible to use a class instead.

  1. <script type="text/javascript">
  2. jQuery(document).ready(function($) {
  3. $("a[rel*=facebox]").facebox();
  4. });
  5. </script>

Finally, you just have to create a link with a rel attribute set to what you\'ve specified in the js setup (in our case rel='facebox').
Then, whatever you specify in the href attribute will be opened in a facebox.

  1. <a href="someimage.jpg" rel="facebox">text</a>

Why not share this here:

  • Tweet this
  • Buy the author a coffee
  • Bump this
  • Digg this
  • Post this on Del.icio.us
  • Post this on StumbleUpon
  • Post this on Reddit
  • Post this on Technorati
  • Post this on Google
  • Post this on Facebook
  • Email this to a friend

You may also like:

  • How to create an Ajax, validated form
  • How to make SEO friendly urls
  • My Favourite MYSQL functions
  • YouTube video manager with PHP, MYSQL & jQuery
  • How to Create Native Admin Tables in WordPress
  • Mootools Facebook Search

Posted Comments

Luke@ Carp Fishing Reels
For some reason all my images have a rel="facebox" attribute even if I don't put this in the code. It is in the page source and the site doesnt validate as a result. Any idea why?
From Luke@ Carp Fishing Reels at 20:24 04/11/10 { Reply }