|
| 1 | +# Facebox |
| 2 | + |
| 3 | +Facebox is a jQuery-based, Facebook-style lightbox which can display images, divs, or entire remote pages. |
| 4 | + |
| 5 | +[See it in action](http://defunkt.github.com/facebox/examples/). |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +[Download the latest release](http://github.com/defunkt/facebox/zipball/master) |
| 10 | + |
| 11 | +## Compatibility |
| 12 | + |
| 13 | +This release relies on a lot of advanced CSS techniques (box-shadow, border-radius, RGBA). That being said, it's compatible with many browsers. |
| 14 | + |
| 15 | +* **Safari 4** |
| 16 | +* **Webkit Nightlies** (Chromium, Chrome) as of 4/17/10 |
| 17 | +* **Firefox 3.5** |
| 18 | +* **IE8** (degraded experience) |
| 19 | +* **IE7** (degraded experience) |
| 20 | +* IE6 - I just don't care |
| 21 | +* Opera - I just don't care |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +Include jQuery, `src/facebox.js` and `src/facebox.css`. Then tell facebox where you've put `src/loading.gif` and `src/closelabel.png` |
| 26 | + |
| 27 | + $.facebox.settings.closeImage = '/images/facebox/closelabel.png' |
| 28 | + $.facebox.settings.loadingImage = '/images/facebox/loading.gif' |
| 29 | + |
| 30 | +Calling facebox() on any anchor tag will do the trick, it's easier to give your Faceboxy links a rel="facebox" and hit them all onDomReady. |
| 31 | + |
| 32 | + jQuery(document).ready(function($) { |
| 33 | + $('a[rel*=facebox]').facebox() |
| 34 | + }) |
| 35 | + |
| 36 | +Any anchor links with `rel="facebox"` with now automatically use facebox: |
| 37 | + |
| 38 | + <a href="#terms" rel="facebox">Terms</a> |
| 39 | + Loads the #terms div in the box |
| 40 | + |
| 41 | + <a href="terms.html" rel="facebox">Terms</a> |
| 42 | + Loads the terms.html page in the box |
| 43 | + |
| 44 | + <a href="terms.png" rel="facebox">Terms</a> |
| 45 | + Loads the terms.png image in the box |
| 46 | + |
| 47 | + |
| 48 | +### Using facebox programmatically |
| 49 | + |
| 50 | + jQuery.facebox('some html') |
| 51 | + jQuery.facebox('some html', 'my-groovy-style') |
| 52 | + |
| 53 | +The above will open a facebox with "some html" as the content. |
| 54 | + |
| 55 | + jQuery.facebox(function($) { |
| 56 | + $.get('blah.html', function(data) { $.facebox(data) }) |
| 57 | + }) |
| 58 | + |
| 59 | +The above will show a loading screen before the passed function is called, |
| 60 | +allowing for a better ajaxy experience. |
| 61 | + |
| 62 | +The facebox function can also display an ajax page, an image, or the contents of a div: |
| 63 | + |
| 64 | + jQuery.facebox({ ajax: 'remote.html' }) |
| 65 | + jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style') |
| 66 | + jQuery.facebox({ image: 'stairs.jpg' }) |
| 67 | + jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style') |
| 68 | + jQuery.facebox({ div: '#box' }) |
| 69 | + jQuery.facebox({ div: '#box' }, 'my-groovy-style') |
| 70 | + |
| 71 | +### Events |
| 72 | + |
| 73 | +Want to close the facebox? Trigger the `close.facebox` document event: |
| 74 | + |
| 75 | + jQuery(document).trigger('close.facebox') |
| 76 | + |
| 77 | +Facebox also has a bunch of other hooks: |
| 78 | + |
| 79 | +* `loading.facebox` |
| 80 | +* `beforeReveal.facebox` |
| 81 | +* `reveal.facebox` (aliased as `afterReveal.facebox`) |
| 82 | +* `init.facebox` |
| 83 | + |
| 84 | +Simply bind a function to any of these hooks: |
| 85 | + |
| 86 | + $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... }) |
| 87 | + |
| 88 | +### Customization |
| 89 | + |
| 90 | +You can give the facebox container an extra class (to fine-tune the display of the facebox) with the facebox[.class] rel syntax. |
| 91 | + |
| 92 | + <a href="remote.html" rel="facebox[.bolder]">text</a> |
| 93 | + |
| 94 | +## Contact & Help |
| 95 | + |
| 96 | +If you have questions, feel free to ask on the [Google Groups Mailing List](http://groups.google.com/group/facebox/). Alternatively if you find a bug, you can [open an issue](http://github.com/defunkt/facebox/issues). |
0 commit comments