轉貼自:http://www.itivy.com/jquery/archive/2011/6/28/jquery-fancybox-usage.html
Fancybox使用方法:
1、引入jquery核心庫和Fancybox插件庫
| 
 1 
2 
 | 
< script  type = "text/javascript"  src = " http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js " ></ script >< script  type = "text/javascript"  src = "/fancybox/jquery.fancybox-1.3.4.pack.js" ></ script > | 
| 
 1 
 | 
< script  type = "text/javascript"  src = "/fancybox/jquery.easing-1.4.pack.js" ></ script > | 
| 
 1 
 | 
< script  type = "text/javascript"  src = "/fancybox/jquery.mousewheel-3.0.4.pack.js" ></ script > | 
| 
 1 
 | 
< link  rel = "stylesheet"  href = "/fancybox/jquery.fancybox-1.3.4.css"  type = "text/css"  media = "screen"  /> | 
A、圖片元素
| 
 1 
 | 
< a  id = "single_image"  href = "image_big.jpg" >< img  src = "image_small.jpg"  alt = "" /></ a > | 
| 
 1 
2 
3 
4 
5 
 | 
< a  id = "inline"  href = "#data" >This shows content of element who has id="data"</ a >< div  style = "display:none" > < div  id = "data" >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</ div ></ div > | 
| 
 1 
2 
3 
4 
5 
 | 
或者 | 
| 
 1 
 | 
 | 
4、最終的jquery初始化代碼
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
 | 
$(document).ready( function () { /* 最基本的,使用了默認配置*/  $( "a#single_image" ).fancybox();  /* 使用了自定義配置*/  $( "a#inline" ).fancybox({ 'hideOnContentClick' : true }); /* 一下配置支持組播放*/  $( "a.group" ).fancybox({ 'transitionIn'  : 'elastic' , 'transitionOut'  : 'elastic' , 'speedIn'  : 600, 'speedOut'  : 200, 'overlayShow'  : false }); }); | 
| 
 1 
2 
3 
4 
5 
6 
7 
 | 
< a  class = "grouped_elements"  rel = "group1"  href = "image_big_1.jpg" >< img  src = "image_small_1.jpg"  alt = "" /></ a >< a  class = "grouped_elements"  rel = "group1"  href = "image_big_2.jpg" >< img  src = "image_small_2.jpg"  alt = "" /></ a > < a  class = "grouped_elements"  rel = "group2"  href = "image_big_3.jpg" >< img  src = "image_small_3.jpg"  alt = "" /></ a >< a  class = "grouped_elements"  rel = "group2"  href = "image_big_4.jpg" >< img  src = "image_small_4.jpg"  alt = "" /></ a >$("a.grouped_elements").fancybox(); | 
| 屬性名 | 默認值 | 簡要說明 | 
|---|---|---|
| padding | 10 | 瀏覽框內邊距,和css中的padding一個意思 | 
| margin | 20 | 瀏覽框外邊距,和css中的margin一個意思 | 
| opacity | false | 如果為true,則fancybox在動畫改變的時候透明度可以跟著改變 | 
| modal | false | 如果為true,則'overlayShow' 會被設成'true' , 'hideOnOverlayClick', 'hideOnContentClick', 'enableEscapeButton', 'showCloseButton' 會被設成'false' | 
| cyclic | false | 如果為true,相冊??會循環播放 | 
| scrolling | 'auto' | 設置overflow的值來創建或隱藏滾動條,可以設置成'auto', 'yes', or 'no' | 
| width | 560 | 設置iframe和swf的寬度,如果'autoDimensions'為'false',這也可以設置普通文本的寬度 | 
| height | 340 | 設置iframe和swf的高度,如果'autoDimensions'為'false',這也可以設置普通文本的高度 | 
| autoScale | true | 如果為true,fancybox可以自適應瀏覽器窗口大小 | 
| autoDimensions | true | 在內聯文本和ajax中,設置是否動態調整元素的尺寸,如果為true,請確保你已經為元素設置了尺寸大小 | 
| centerOnScroll | false | 如果為true,當你滾動滾動條時,fancybox將會一直停留在瀏覽器中心 | 
| ajax | { } | 和jquery的ajax調用選項一樣注意: 'error' and 'success'這兩個回調事件會被fancybox重寫 | 
| swf | {wmode: 'transparent'} | swf的設置選項 | 
| hideOnOverlayClick | true | 如果為true則點擊遮罩層關閉fancybox | 
| hideOnContentClick | false | 如果為true則點擊播放內容關閉fancybox | 
| overlayShow | true | 如果為true,則顯示遮罩層 | 
| overlayOpacity | 0.3 | 遮罩層的透明度(範圍0-1) | 
| overlayColor | '#666' | 遮罩層的背景顏色 | 
| titleShow | true | 如果為true,則顯示標題 | 
| titlePosition | 'outside' | 設置標題顯示的位置.可以設置成'outside', 'inside' 或'over' | 
| titleFormat | null | 可以自定義標題的格式 | 
| transitionIn, transitionOut | 'fade' | 設置動畫效果. 可以設置為'elastic', 'fade' 或'none' | 
| speedIn, speedOut | 300 | fade 和elastic 動畫切換的時間間隔, 以毫秒為單位 | 
| changeSpeed | 300 | 切換時fancybox尺寸的變化時間間隔(即變化的速度),以毫秒為單位 | 
| changeFade | 'fast' | 切換時內容淡入淡出的時間間隔(即變化的速度) | 
| easingIn, easingOut | 'swing' | 為elastic 動畫使用Easing | 
| showCloseButton | true | 如果為true,則顯示關閉按鈕 | 
| showNavArrows | true | 如果為true,則顯示上一張下一張導航箭頭 | 
| enableEscapeButton | true | 如果為true,則啟用ESC來關閉fancybox | 
| onStart | null | 回調函數,加載內容是觸發 | 
| onCancel | null | 回調函數,取消加載內容後觸發 | 
| onComplete | null | 回調函數,加載內容完成後觸發 | 
| onCleanup | null | 回調函數,關閉fancybox前觸發 | 
| onClosed | null | 回調函數,關閉fancybox後觸發 | 
 


















