Featherlight is a very lightweight jQuery lightbox plugin. For more information and demos, visit the official website.
- Simple yet flexible
- Image, Ajax, iFrame and custom content support
- Gallery Extension
- Minimal CSS
- Name-spaced CSS and JavaScript
- Responsive
- Customizable via configuration object
Here you'll find a list of all the changes and you can also download old releases or the master including all the latest bling.
All styling is done using CSS so you'll want to include the Featherlight CSS in your head.
<link href="//rawgithub.com/noelboss/featherlight/master/src/featherlight.min.css" type="text/css" rel="stylesheet" title="Featherlight Styles" />
Be aware that Featherlight uses very unspecific CSS selectors to help you overwrite every aspect. This means in turn, that if you're not following a modularized approach to write CSS (which you should! It's terrific!) and have many global and specific definitions (read ID's and such – which you shouldn't), these definitions can break the Featherlight styling.
Featherlight requires jQuery version 1.7.0 or higher. It's recommended to include the javascript at the bottom of the page before the closing </body>
tag.
<script src="//code.jquery.com/jquery-latest.js"></script>
<script src="//rawgithub.com/noelboss/featherlight/master/src/featherlight.min.js" type="text/javascript" charset="utf-8"></script>
By default, featherlight acts on all elements using the 'data-featherlight' attribute. An element with this attribute triggers the lightbox. The value of the attribute acts as selector for an element that's opened as lightbox.
<a href="#" data-featherlight="#mylightbox">Open element in lightbox</a>
<div id="mylightbox">This div will be opened in a lightbox</div>
Featherlight is smart. 'data-featherlight' can also contain a link to an image, an ajax-url or even DOM code:
<span data-featherlight="myimage.png">Open image in lightbox</a>
<span data-featherlight="myhtml.html .selector">Open ajax content in lightbox</a>
<span data-featherlight="<p>Fancy DOM Lightbox!</p>">Open some DOM in lightbox</span>
it also works with links using href and the "image" and "ajax" keywords (this can also be manually set with the configuration options type.image
and type.ajax
):
<a href="myimage.png" data-featherlight="image">Open image in lightbox</a>
<a href="myhtml.html .selector" data-featherlight="ajax">Open ajax content in lightbox</a>
By default, Featherlight initializes all elements matching defaults.selector
on document ready. If you want to prevent this, set $.featherlight.defaults.autostart
to false before the DOM is ready.
You can bind the Featherlight events on any element using the following code:
$('.myElement').featherlight(configuration, $content);
It will then look for the targetAttr
(by default "data-featherlight") on this element and use its value to find the content that will be opened as lightbox when you click on the element.
configuration – Object: Object to configure certain aspects of the plugin. See Configuration.
$content – jQuery Object or String: You can manually pass a jQuery object or a string containing HTML Code to be opened in the ligthbox.
In cases where you don't want an Element to act as Trigger you can call Featherlight manually. You can use this for example in an ajax callback to display the response data.
$.featherlight($content, configuration);
$content – jQuery Object or String: You can manually pass a jQuery object or a string containing HTML Code to be opened in the ligthbox.
configuration – Object: Object to configure certain aspects of the plugin. See Configuration.
Featherlight comes with a bunch of configuration-options which make it very flexible. Pass your options in an object to the function call or overwrite $.featherlight.defaults. This is the whole default object:
/* you can access and overwrite all defaults using $.fl.defaults */
defaults: {
autostart: true, /* Initialize all links with that match "selector" on document ready */
namespace: 'featherlight', /* Name of the events and css class prefix */
selector: '[data-featherlight]', /* Elements that trigger the lightbox */
context: 'body', /* Context used to search for the lightbox content and triggers */
type: { /* Manually set type of lightbox. Otherwise, it will check for the targetAttrs value. */
image: false,
ajax: false
},
targetAttr: 'data-featherlight', /* Attribute of the triggered element that contains the selector to the lightbox content */
variant: null, /* Class that will be added to change look of the lightbox */
resetCss: false, /* Reset all css */
background: null, /* Custom DOM for the background, wrapper and the closebutton */
openTrigger: 'click', /* Event that triggers the lightbox */
closeTrigger: 'click', /* Event that triggers the closing of the lightbox */
openSpeed: 250, /* Duration of opening animation */
closeSpeed: 250, /* Duration of closing animation */
closeOnBg: true, /* Close lightbox on click on the background */
closeOnEsc: true, /* Close lightbox when pressing esc */
closeIcon: '✕', /* Close icon */
beforeOpen: null, /* Called before open. can return false to prevent opening of lightbox. Gets event as parameter, this contains all data */
beforeClose: null, /* Called before close. can return false to prevent opening of lightbox. Gets event as parameter, this contains all data */
afterOpen: null, /* Called after open. Gets event as parameter, this contains all data */
afterClose: null, /* Called after close. Gets event as parameter, this contains all data */
open: function(event){ /* opens the lightbox "this" contains $instance with the lightbox, and with the config */
$.proxy($.featherlight.methods.open, this, event)();
},
close: function(event){ /* closes the lightbox "this" contains $instance with the lightbox, and with the config */
$.proxy($.featherlight.methods.close, this, event)();
}
}
================================================
autostart – Boolean: true
By default, Featherlight finds all elements that match "selector" and binds the open and close functions. To disable, set $.featherlight.defaults.autostart = false; before the document ready event is fired.
================================================
namespace – String: 'featherlight'
All functions bound to elements are namespaced. This is also used to prefix all CSS classes for the background, the content-wrapper and the close button.
================================================
selector – String: '[data-featherlight]'
Selector used to collect triggering elements when document is ready.
================================================
context – String: 'body'
Context used for selecting elements matching "selector". Useful of you only want to bind featherbox to parts of the DOM, for example in content loaded via ajax.
================================================
type – Object: image: false, ajax: false
The type object allows you to manually set what type the lightbox is. Set the value of type.image or type.ajax to true. Otherwise, the value from targetAttr will be to determine the type of the lightbox. Example:
$('.image-lightbox', $('.gallery')).featherlight({
type: {
image: true
}
});
================================================
targetAttr – String: 'data-featherlight'
Attribute on the triggering element pointing to the target element that will be opened in the lightbox.
================================================
variant – String: null
Pass your own CSS class to adjust the styling of the lightbox according to your need. You can also use the data-featherlight-variant
attribute on the element triggering the lightbox.
================================================
resetCss – Boolean: false
Set this to true to remove all default css and start from designing scratch.
================================================
openTrigger & closeTrigger – String: 'click'
Events that are used to open or close the lightbox. The close event is bound to the close button and to the lightbox background (if enabled)
================================================
openSpeed & closeSpeed – Integer or String: 250
Defines the speed for the opening and close animations. Values allowed are jQuery animation durations. Avoid the usage of 0 since this would cause a reversal of time and the end of the world! (Okay, kidding, just the closing callback would not be fired and unused ghost-DOM would linger around, but still.)
================================================
closeOnBg – Boolean: true
If true, the close event is also bound to the background
================================================
closeOnEsc – Boolean: true
If true, the lightbox is closed when pressing the ESC key
================================================
closeIcon – String: ✕`;
Oh the naming...
================================================
background – DOM String: null
You can provide the wrapping DOM. This is a bit tricky and just for the advanced users. It's recommended to study the plugin code. But you need to provide an element with a "{namespace}-close" class: the content of the lightbox will be added after this element.
================================================
beforeOpen, beforeClose – Function: null
Called before the open or close method is executed. This function can return false to prevent open or close method from execution. ´this´ is an object and contains the triggering DOM element (if existing) and the related Featherlight objects.
// example
beforeOpen: function(event){
console.log(this); // this contains all related elements
returm false; // prevent lightbox from opening
}
================================================
afterOpen, afterClose – Function: null
Called after the open or close method is executed. ´this´ is an object and contains the triggering DOM element (if existing) and the related Featherlight objects.
// example
afterOpen: function(event){
console.log(this); // this contains all related elements
alert(this.$content.hasClass('true')); // alert class of content
}
================================================
open – Function
This is the open function used to open the lightbox. It receives the event object. ´this´ is an object and contains the triggering DOM element (if existing) and the related Featherlight objects.
open: function(event){
================================================
close – Function
This is the close function used to close the lightbox. It receives the event object. ´this´ is an object and contains the triggering DOM element (if existing) and the related Featherlight objects.
close: function(event){
$.proxy($.featherlight.methods.close, this, e)();
}
All of Featherlight's methods are stored in $.featherlight.methods and can therefore be overwritten like the configuration defaults.
methods: { /* you can access and overwrite all methods using */
/* setup iterates over a single instance of featherlight and prepares the background and binds the events */
setup: function(config, content){
// ...
},
/* this method prepares the content and converts it into a jQuery object */
getContent: function(){
// ...
},
/* opens the lightbox "this" contains $instance with the lightbox, and with the config */
open: function(event){
// ...
},
/* closes the lightbox "this" contains $instance with the lightbox, and with the config */
close: function(event){
// ...
}
}
You can overwrite a function like this:
$.featherlight.methods.open = function() { alert('open!'); }
Check the source code for more details.
<a href="#targetElement" class="fl">Open</a>
<div id="targetElement">Lightbox</div>
$('a.fl').featherlight({
targetAttr: 'href'
});
Us a link and point the data-featherlight attribute to the desired attribute which contains the link...
<a href="myimage.jpg" data-featherlight="image">Open Image</a>
...or directly provide the link as the data-featherlight attribute:
<span data-featherlight="myimage.jpg">Open Image</span>
Use Featherlight with ajax using 'ajax' keyword or providing a url. It even supports selecting elements inside the response document.
<a href="url.html .jQuery-Selector" data-featherlight="ajax">Open Ajax Content</a>
or you can provide the link directly as the featherlight-attribute:
<a href="url.html .jQuery-Selector" data-featherlight="ajax">Open Ajax Content</a>
Featherlight was created to be as small and simple as possible. Therefore it does not provide all functionality imaginable. But, since its small and simple, it can be extended easily. featherlight.gallery.js is a small extension that turns your set of links into a gallery.
$('a.gallery').featherlightGallery({
openSpeed: 300
});
The gallery also has a range of configuration options and the following defaults:
gallery: {
previous: '◀', /* Code that is used as previews icon */
next: '▶', /* Code that is used as next icon */
fadeIn: 100, /* fadeIn speed when image is loaded */
fadeOut: 300 /* fadeOut speed before image is loaded */
}
Example:
$('a.gallery').featherlightGallery({
gallery: {
previous: '«',
next: '»',
fadeIn: 300
},
openSpeed: 300
});
Simply include the extension CSS and JavaScript Files after the regular featherlight files like this:
<link href="//rawgithub.com/noelboss/featherlight/master/src/featherlight.min.css" type="text/css" rel="stylesheet" title="Featherlight Styles" />
<link href="//rawgithub.com/noelboss/featherlight/master/src/featherlight.gallery.min.css" type="text/css" rel="stylesheet" title="Featherlight Gallery Styles" />
Add the JavaScript at the bottom of the body:
<script src="//code.jquery.com/jquery-latest.js"></script>
<script src="//rawgithub.com/noelboss/featherlight/master/src/featherlight.min.js" type="text/javascript" charset="utf-8"></script>
<script src="//rawgithub.com/noelboss/featherlight/master/src/featherlight.gallery.min.js" type="text/javascript" charset="utf-8"></script>
Check out the example here: Gallery with Featherlight
If you want the background in IE8 to be translucent, use data:image before the rgba background:
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAKQWlDQ1BJQ0MgUHJvZmlsZQAASA2dlndUU9kWh8+9N73QEiIgJfQaegkg0jtIFQRRiUmAUAKGhCZ2RAVGFBEpVmRUwAFHhyJjRRQLg4Ji1wnyEFDGwVFEReXdjGsJ7601896a/cdZ39nnt9fZZ+9917oAUPyCBMJ0WAGANKFYFO7rwVwSE8vE9wIYEAEOWAHA4WZmBEf4RALU/L09mZmoSMaz9u4ugGS72yy/UCZz1v9/kSI3QyQGAApF1TY8fiYX5QKUU7PFGTL/BMr0lSkyhjEyFqEJoqwi48SvbPan5iu7yZiXJuShGlnOGbw0noy7UN6aJeGjjAShXJgl4GejfAdlvVRJmgDl9yjT0/icTAAwFJlfzOcmoWyJMkUUGe6J8gIACJTEObxyDov5OWieAHimZ+SKBIlJYqYR15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