Book Image

Instant Fancybox

By : Kyle Diedrick
Book Image

Instant Fancybox

By: Kyle Diedrick

Overview of this book

Fancybox is a lightweight, highly customizable jQuery plugin for displaying modal dialogs. Fancybox is incredibly versatile; it works with all sorts of different content including images, videos, iFrames, custom HTML, and even SWF files. Fancybox is also very easy to customize, making it a great tool for any pop-up-like feature. Instant Fancybox is a hands-on guide which shows you how to use and customize the Fancybox plugin. The book provides step-by-step tutorials covering everything from simple installation to complex settings and features. This makes it a great way to get familiar with and ultimately master the Fancybox plugin. This book walks you through how to get the most out of the Fancybox plugin for jQuery, starting with the installation of the plugin and how to work with the JavaScript events that Fancybox triggers. You will learn everything you need to know about setting up Fancybox to show images, image galleries and slideshows, videos, and other content. You will also learn about the settings available within Fancybox and how to leverage them to make the Fancybox popup do exciting things. The Fancybox plugin has much to offer, and this book covers all of the features it provides. This book will provide you with all the information you will need to use the Fancybox plugin effectively.
Table of Contents (7 chapters)

Preface

Instant Fancybox is a jQuery lightbox plugin, which is very versatile and customizable. A lightbox is essentially an in-page pop-up window. These have become the de facto way to show pop-up content on the web for various reasons, including interaction between lightboxes and the main content via JavaScript. Actual pop-up windows are frequently blocked by browsers because people find actual pop-up windows (if they are not blocked) to be annoying. Fancybox has several very cool features that make it a powerful lightbox tool such as built-in image galleries and slide shows. It is responsive (that is, it adjusts to the size of the browser window), it can load many different types of content, and it has a very powerful API and settings system that allow it to be easily extended and customized.

This book covers Version 2 of the plugin. It will cover all of the functionality that Fancybox provides, as well as a step-by-step walkthrough of some of the ways to use Fancybox. The book starts with installing the plugin and works its way from loading a simple image all the way to adding custom functionality around the Fancybox pop up.

What this book covers

Installing Fancybox (Simple), will show how to download and install the code for the Fancybox plugin in an HTML file.

Fancybox with a single image (Simple), will start out with a simple first crack at Fancybox. The simplest way to begin learning Fancybox is to create a basic HTML page, which shows a single image in Fancybox.

Creating an image gallery (Simple), will show how to create an image gallery that can be expanded inside Fancybox. The image gallery can then be viewed as an image slideshow.

Displaying YouTube videos (Intermediate), will show how to display a YouTube video inside Fancybox. We also cover getting the necessary information about the video from the YouTube website.

Loading content via AJAX (Intermediate), will show how to display an HTML file from a web server using Fancybox's AJAX content type. We'll also cover changing the error message that Fancybox displays if it cannot load the content.

Loading additional types of content (Intermediate), will show how Fancybox can load other types of content beyond just images, videos, and asynchronous HTML. We will also look at using Fancybox to load any iframe content, Flash (SWF) files, and inline HTML.

Adding thumbnails to a gallery (Simple), will show how Fancybox can display thumbnails of the images in our gallery. We will also look at changing the position of the thumbnails and changing where the thumbnail images are loaded from.

Adding buttons to image slideshows (Simple), will show how Fancybox can display buttons to interact with image slide shows. We'll take a look at using Fancybox to display these buttons and at ways we can customize them.

Customizing other helpers (Intermediate), will introduce helpers, which are additional features that are optional but technically a part of Fancybox. Here we take a look at two more helpers: image title and the transparent overlay.

Modifying styles and layout (Intermediate), will cover the ways Fancybox allows us to change the look and positioning of the Fancybox pop up.

Changing slideshow settings (Advanced), will look at changing all of the slide show related settings in Fancybox. This includes play speed, looping, automatically playing, and preloading images.

Adding custom styles (Intermediate), will show how Fancybox provides the ability to add custom classes to the Fancybox HTML. Here we take a look at how to add custom classes as well as the classes Fancybox uses by default.

Changing animation effects (Intermediate), will show how Fancybox allows us to change all of the animation effects. We take a look at changing all of the effects for opening and closing Fancybox as well as changing the effects for moving around inside an image slide show.

Changing keyboard shortcuts (Advanced), will show how Fancybox provides a handful of useful keyboard shortcuts by default. We will investigate changing these defaults as well as adding our own keyboard shortcuts while keeping the defaults.

Interacting with Fancybox (Advanced), will show how Fancybox provides a number of ways to open, close, or otherwise interact with the Fancybox pop up programmatically. We take a look at using JavaScript code to open and close the Fancybox pop up.

Manipulating image slideshows (Advanced), will show how Fancybox also provides API functions to interact with image slideshows. In this section we create some custom links, which trigger the standard next, previous, and play/pause functionality.

Listening for Fancybox events (Advanced), will show how to use the Fancybox callback events to run code at key points of the Fancybox pop up's life, including the following: just after it is displayed, just before it is closed, and just as the slideshow is paused. We also list all of the callback events that Fancybox provides.

What you need for this book

For this book you will need at least a web browser and a text editor. For the recipe on AJAX content you will also need a web server which can host an HTML file. You will also need an Internet connection to download the Fancybox plugin and jQuery JavaScript and CSS files.

Who this book is for

This book is aimed at frontend web developers looking to learn about the jQuery plugin Fancybox. It is expected that the reader should have some knowledge of JavaScript syntax as well as jQuery. It is also expected that the reader should have a basic understanding of HTML and CSS. However, I believe anyone with even a little experience in JavaScript, HTML, and CSS can pick up this book and learn how to use the Fancybox plugin.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, and user input are shown as follows: "Create a folder called images alongside the index.html file and put the image in the folder."

A block of code is set as follows:

<!DOCTYPE html>
<html>
<head>
    <title>Chapter 1</title>
</head>
<body>
    <h1>Installing Fancybox</h1>
</body>
</html>

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "click on the share tab as shown in the following screenshot:"

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.