README.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. fancyBox
  2. ========
  3. fancyBox is a tool that offers a nice and elegant way to add zooming functionality for images, html content and multi-media on your webpages.
  4. More information and examples: http://www.fancyapps.com/fancybox/
  5. License: http://www.fancyapps.com/fancybox/#license
  6. Copyright (c) 2012 Janis Skarnelis - janis@fancyapps.com
  7. How to use
  8. ----------
  9. To get started, download the plugin, unzip it and copy files to your website/application directory.
  10. Load files in the <head> section of your HTML document. Make sure you also add the jQuery library.
  11. <head>
  12. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
  13. <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css" media="screen" />
  14. <script type="text/javascript" src="/fancybox/jquery.fancybox.pack.js"></script>
  15. </head>
  16. Create your links with a `title` if you want a title to be shown, and add a class:
  17. <a href="large_image.jpg" class="fancybox" title="Sample title"><img src="small_image.jpg" /></a>
  18. If you have a set of related items that you would like to group,
  19. additionally include a group name in the `rel` (or `data-fancybox-group`) attribute:
  20. <a href="large_1.jpg" class="fancybox" rel="gallery" title="Sample title 1"><img src="small_1.jpg" /></a>
  21. <a href="large_2.jpg" class="fancybox" rel="gallery" title="Sample title 1"><img src="small_2.jpg" /></a>
  22. Initialise the script like this:
  23. <script>
  24. $(document).ready(function() {
  25. $('.fancybox').fancybox();
  26. });
  27. </script>
  28. May also be passed an optional options object which will extend the default values. Example:
  29. <script>
  30. $(document).ready(function() {
  31. $('.fancybox').fancybox({
  32. padding : 0,
  33. openEffect : 'elastic'
  34. });
  35. });
  36. </script>
  37. Tip: Automatically group and apply fancyBox to all images:
  38. $("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.png'],a[href$='.gif']").attr('rel', 'gallery').fancybox();
  39. Script uses the `href` attribute of the matched elements to obtain the location of the content and to figure out content type you want to display.
  40. You can specify type directly by adding classname (fancybox.image, fancybox.iframe, etc) or `data-fancybox-type` attribute:
  41. //Ajax:
  42. <a href="/example.html" class="fancybox fancybox.ajax">Example</a>
  43. //or
  44. <a href="/example.html" class="fancybox" data-fancybox-type="ajax">Example</a>
  45. //Iframe:
  46. <a href="example.html" class="fancybox fancybox.iframe">Example</a>
  47. //Inline (will display an element with `id="example"`)
  48. <a href="#example" class="fancybox">Example</a>
  49. //SWF:
  50. <a href="example.swf" class="fancybox">Example</a>
  51. //Image:
  52. <a href="example.jpg" class="fancybox">Example</a>
  53. Note, ajax requests are subject to the [same origin policy](http://en.wikipedia.org/wiki/Same_origin_policy).
  54. If fancyBox will not be able to get content type, it will try to guess based on 'href' and will quit silently if would not succeed.
  55. (this is different from previsous versions where 'ajax' was used as default type or an error message was displayed).
  56. Advanced
  57. --------
  58. ### Helpers
  59. Helpers provide a simple mechanism to extend the capabilities of fancyBox. There are two built-in helpers - 'overlay' and 'title'.
  60. You can disable them, set custom options or enable other helpers. Examples:
  61. //Disable title helper
  62. $(".fancybox").fancybox({
  63. helpers: {
  64. title: null
  65. }
  66. });
  67. //Disable overlay helper
  68. $(".fancybox").fancybox({
  69. helpers: {
  70. overlay : null
  71. }
  72. });
  73. //Change title position and overlay color
  74. $(".fancybox").fancybox({
  75. helpers: {
  76. title : {
  77. type : 'inside'
  78. },
  79. overlay : {
  80. css : {
  81. 'background' : 'rgba(255,255,255,0.5)'
  82. }
  83. }
  84. }
  85. });
  86. //Enable thumbnail helper and set custom options
  87. $(".fancybox").fancybox({
  88. helpers: {
  89. thumbs : {
  90. width: 50,
  91. height: 50
  92. }
  93. }
  94. });
  95. ### API
  96. Also available are event driven callback methods. The `this` keyword refers to the current or upcoming object (depends on callback method). Here is how you can change title:
  97. $(".fancybox").fancybox({
  98. beforeLoad : function() {
  99. this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
  100. /*
  101. "this.element" refers to current element, so you can, for example, use the "alt" attribute of the image to store the title:
  102. this.title = $(this.element).find('img').attr('alt');
  103. */
  104. }
  105. });
  106. It`s possible to open fancyBox programmatically in various ways:
  107. //HTML content:
  108. $.fancybox( '<div><h1>Lorem Lipsum</h1><p>Lorem lipsum</p></div>', {
  109. title : 'Custom Title'
  110. });
  111. //DOM element:
  112. $.fancybox( $("#inline"), {
  113. title : 'Custom Title'
  114. });
  115. //Custom object:
  116. $.fancybox({
  117. href: 'example.jpg',
  118. title : 'Custom Title'
  119. });
  120. //Array of objects:
  121. $.fancybox([
  122. {
  123. href: 'example1.jpg',
  124. title : 'Custom Title 1'
  125. },
  126. {
  127. href: 'example2.jpg',
  128. title : 'Custom Title 2'
  129. }
  130. ], {
  131. padding: 0
  132. });
  133. There are several methods that allow you to interact with and manipulate fancyBox, example:
  134. //Close fancybox:
  135. $.fancybox.close();
  136. There is a simply way to access wrapping elements using JS:
  137. $.fancybox.wrap
  138. $.fancybox.skin
  139. $.fancybox.outer
  140. $.fancybox.inner
  141. You can override CSS to customize the look. For example, make navigation arrows always visible,
  142. change width and move them outside of area (use this snippet after including fancybox.css):
  143. .fancybox-nav span {
  144. visibility: visible;
  145. }
  146. .fancybox-nav {
  147. width: 80px;
  148. }
  149. .fancybox-prev {
  150. left: -80px;
  151. }
  152. .fancybox-next {
  153. right: -80px;
  154. }
  155. In that case, you might want to increase space around box:
  156. $(".fancybox").fancybox({
  157. margin : [20, 60, 20, 60]
  158. });
  159. Bug tracker
  160. -----------
  161. Have a bug? Please create an issue on GitHub at https://github.com/fancyapps/fancyBox/issues