colorbox 彈出層 jquery

colorbox 彈出層 jquery

$(".inline").colorbox({inline:true, width:"50%"});<p><a class='inline' href="#inline_content">Inline HTML</a></p><div style='display:none'><div id='inline_content' style='padding:10px; background:#fff;'><p><strong>This content comes from a hidden element on this page.</strong></p><p>The inline option preserves bound JavaScript events and changes, and it puts the content back where it came from when it is closed.</p></div></div>

在上面的代碼中,每種使用方式都有說明,從代碼中可以看出, colorbox 使用起來是非常的簡單。
colorbox 還提供了很多的屬性、方法和事件,可以讓我們更加方式的就用 colorbox,下面是一個從網上找的一個中文的參考列表:
KEY
設置的值

DEFAULT
默認值

DESCRIPTION
介紹

transition

“elastic”

The transition type. Can be set to “elastic”, “fade”, or “none”.
過渡效果,可以是”elastic”, “fade”, or “none”.

speed

350

Sets the speed of the fade and elastic transitions, in milliseconds.
設置過渡效果的持續時間,毫秒

href

false

This can be used as an alternative anchor URL or to associate a URL for non-anchor elements such as images or form buttons. Example:
$(‘h1′).colorbox({href:”welcome.html”})
這個用來設置一個錨標記的值或者一個不是錨的元素,例如圖像或者表單的按鈕,例如:

title

false

This can be used as an anchor title alternative for ColorBox.
這可以為Colorbox設置一個標題

rel

false

This can be used as an anchor rel alternative for ColorBox. This allows the user to group any combination of elements together for a gallery, or to override an existing rel so elements are not grouped together. Example:
$(‘#example a’).colorbox({rel:’group1′})
這個可以根據元素的rel屬性設置要顯示的元素集合,也可以覆蓋一個存在的rel屬性

width

false

Set a fixed total width. This includes borders and buttons. Example: “100%”, “500px”, or 500
設置寬度,包括邊框和按鈕

height

false

Set a fixed total height. This includes borders and buttons. Example: “100%”, “500px”, or 500
設置高度,包括邊框和按鈕

innerWidth

false

This is an alternative to ‘width’ used to set a fixed inner width. This excludes borders and buttons. Example: “50%”, “500px”, or 500
這個可以設定一個固定的內大小,包括邊框和按鈕

innerHeight

false

This is an alternative to ‘height’ used to set a fixed inner height. This excludes borders and buttons. Example: “50%”, “500px”, or 500
這個可以設定一個固定的內高度,包括邊框和按鈕

initialWidth

300

Set the initial width, prior to any content being loaded.
設置初始化寬度

initialHeight

100

Set the initial height, prior to any content being loaded.
設置初始化高度

maxWidth

false

Set a maximum width for loaded content. Example: “100%”, 500, “500px”
設置內容的最大寬度

maxHeight

false

Set a maximum height for loaded content. Example: “100%”, 500, “500px”
設置內容的最大高度

scalePhotos

true

If ‘true’ and if maxWidth, maxHeight, innerWidth, innerHeight, width, or height have been defined, ColorBox will scale photos to fit within the those values.
如果是true且maxWidth, maxHeight, innerWidth, innerHeight, width, 或者 height 被設置,Colorbox會縮放圖片以使用邊框

scrolling

true

If ‘false’ ColorBox will hide scrollbars for overflowing content. This could be used on conjunction with the resize method (see below) for a smoother transition if you are appending content to an already open instance of ColorBox.
如果是false,Colorbox不會為了溢出元素設置滾動條

iframe

false

If ‘true’ specifies that content should be displayed in an iFrame.
如果是true,元素會在Iframe中顯示

inline

false

If ‘true’ a jQuery selector can be used to display content from the current page. Example:
$(“#inline”).colorbox({inline:true, href:”#myForm”});
如果是true,jquery選擇器可以用來選擇要顯示的元素。例如:

html

false

This allows an HTML string to be used directly instead of pulling content from another source (ajax, inline, or iframe). Example:
$.fn.colorbox({html:’<p>Hello</p>’});
這個是直接讓你顯示HTML代碼,例如:

photo

false

If true, this setting forces ColorBox to display a link as a photo. Use this when automatic photo detection fails (such as using a url like ‘photo.PHP’ instead of ‘photo.jpg’, ‘photo.jpg#1′, or ‘photo.jpg?pic=1′)
如果為true,ColorBox只會把元素按照圖片顯示,防止類似photo.php?pic=1這樣的連接被誤認為是網頁

opacity

0.85

The overlay opacity level. Range: 0 to 1.
遮罩層不透明度 從0-1之間取值

open

false

If true, the lightbox will automatically open with no input from the visitor.
如果為true,ColorBox會自動開啟

preloading

true

Allows for preloading of ‘Next’ and ‘Previous’ content in a shared relation group (same values for the ‘rel’ attribute), after the current content has finished loading. Set to ‘false’ to disable.
如果為True,ColorBox會自動預載要顯示圖片

overlayClose

true

If true, enables closing ColorBox by clicking on the background overlay.
為true單擊遮罩層就可以把ColorBox關閉

slideshow

false

If true, adds an automatic slideshow to a content group / gallery.
為True,會自動滾動圖片

slideshowSpeed

2500

Sets the speed of the slideshow, in milliseconds.
設置時間,毫秒

slideshowAuto

true

If true, the slideshow will automatically start to play.
為tuue,滑動會自動開始

slideshowStart

“start slideshow”

Text for the slideshow start button.
開始自動滑動按鈕的文本

slideshowStop

“stop slideshow”

Text for the slideshow stop button
停止自動滑動按鈕的文本

current

“{current} of {total}”

Text format for the content group / gallery count. {current} and {total} are detected and replaced with actual numbers while ColorBox runs.
文本內容:現在正在顯示的元素序號,格式”{現在} of {總計}”

previous

“previous”

Text for the previous button in a shared relation group (same values for ‘rel’ attribute).
“上一個”按鈕的文本

next

“next”

Text for the next button in a shared relation group (same values for ‘rel’ attribute).
“下一個”按鈕的文本

close

“close”

Text for the close button. The ‘Esc’ key will also close ColorBox.
“關閉”按鈕的文本

onOpen

false

Callback that fires right before ColorBox begins to open.
下面幾個都是在XXX時候要執行的函數,不用多說,一看就會

onLoad

false

Callback that fires right before attempting to load the target content.

onComplete

false

Callback that fires right after loaded content is displayed.

onCleanup

false

Callback that fires at the start of the close process.

onClosed

false

Callback that fires once ColorBox is closed.

上面列表轉載自:http://hi.baidu.com/234000/

(原創)關于一款優秀的Jquery插件-Colorbox的官方用法翻譯
2010年01月17日 星期日 11:13
原創文章,如果您需要轉載,請您注明來源來自 http://hi.baidu.com/234000/ 謝謝!
Colorbox:http://colorpowered.com/colorbox/
Colorbox是一個能在你的瀏覽器窗口中創建一個模態對話框的程序。。。也就是類似大家經常看到的那種遮罩層+提示框的樣子。當然,你也可以讓遮罩層不顯示的。
在以前,用于Jquery的類似插件應該毫無疑問是Thickbox。不過前一陣子去Jquery Plugins看的時候發現Thickbox已經停止了更新,且Jquery官方推薦了幾個Thickbox的替代品,我最終選擇了Colorbox,因為它十分的簡單易用和強大。
以下是Colorbox的官方介紹翻譯,希望對大家有所幫助。
——————————————————————————————————————————
Colorbox
Jquery的一個輕量的,可自定義的 lightbox 插件。
為什么選擇Colorbox?
Supports photos, photo groups, slideshow, ajax, inline, and iframed content.
支持圖片,圖片組,圖片滑動觀看,ajax,行內元素和iframe內容

· Lightweight: less than 9KB of javascript.
· 十分輕量,只有不到9KB大小
· Appearance is controlled through CSS so users can restyle the box.
· 外觀可以通過CSS進行控制
· Behavior settings can be over-written without altering the ColorBox javascript file.
· 可以直接覆蓋ColorBox的行為設置而不用改ColorBox的js文件
· Can be extended with callbacks & event-hooks without altering the source files.
· 可以直接加上回調函數和事件鉤子而不用更改它的源代碼
· Completely unobtrusive, options are set in the JS and require no changes to existing HTML.
· 非入侵式操作,選項可以在JS中設置而不用更改HTML
· Preloads background images and can preload upcoming images in a photo group.
· 可以預載背景圖片和圖片組中的圖片
· Written in jQuery plugin format and can be chained with other jQuery commands.
· 用Jquery插件格式編寫,可以使用鏈式操作
· Generates W3C valid XHTML and adds no JS global variables & passes JSLint.
· 語法通過W3C和XHTML認證,沒有添加JS的全局變量
· Released under the MIT License.
· 在 MIT License下發布
Tested In: Firefox 2 & 3, Safari 3 & 4, Opera 9, Chrome, Internet Explorer 6, 7, 8.
在Firefox 2 & 3, Safari 3 & 4, Opera 9, Chrome, Internet Explorer 6, 7, 8.下運行良好
Instructions
介紹
The colorbox() function takes a key/value object and an optional callback.
colorbox()函數使用一堆key/value對象和一個可選的callback函數
Format: $('selector').colorbox({key:value}, callback);
格式?:$('selector').colorbox({key:value}, callback);
Example: $('a.gallery').colorbox({transition:'fade', speed:500});
例子: $('a.gallery').colorbox({transition:'fade', speed:500});
Example: $('button').colorbox({href:"thankyou.html"});
還是例子:$('button').colorbox({href:"thankyou.html"});
Follow the source code on the demonstration pages for plenty of examples.
在Colorbox的演示頁面還有很多例子
Key
設置的值

Default
默認值

Description
介紹

transition

"elastic"

The transition type. Can be set to "elastic", "fade", or "none".
過渡效果,可以是"elastic", "fade", or "none".

speed

350

Sets the speed of the fade and elastic transitions, in milliseconds.
設置過渡效果的持續時間,毫秒

href

false

This can be used as an alternative anchor URL or to associate a URL for non-anchor elements such as images or form buttons. Example:$('h1').colorbox({href:"welcome.html"})
這個用來設置一個錨標記的值或者一個不是錨的元素,例如圖像或者表單的按鈕,例如:

title

false

This can be used as an anchor title alternative for ColorBox.
這可以為Colorbox設置一個標題

rel

false

This can be used as an anchor rel alternative for ColorBox. This allows the user to group any combination of elements together for a gallery, or to override an existing rel so elements are not grouped together. Example:$('#example a').colorbox({rel:'group1'})
這個可以根據元素的rel屬性設置要顯示的元素集合,也可以覆蓋一個存在的rel屬性

width

false

Set a fixed total width. This includes borders and buttons. Example: "100%", "500px", or 500
設置寬度,包括邊框和按鈕

height

false

Set a fixed total height. This includes borders and buttons. Example: "100%", "500px", or 500
設置高度,包括邊框和按鈕

innerWidth

false

This is an alternative to 'width' used to set a fixed inner width. This excludes borders and buttons. Example: "50%", "500px", or 500
這個可以設定一個固定的內大小,包括邊框和按鈕

innerHeight

false

This is an alternative to 'height' used to set a fixed inner height. This excludes borders and buttons. Example: "50%", "500px", or 500
這個可以設定一個固定的內高度,包括邊框和按鈕

initialWidth

300

Set the initial width, prior to any content being loaded.
設置初始化寬度

initialHeight

100

Set the initial height, prior to any content being loaded.
設置初始化高度

maxWidth

false

Set a maximum width for loaded content. Example: "100%", 500, "500px"
設置內容的最大寬度

maxHeight

false

Set a maximum height for loaded content. Example: "100%", 500, "500px"
設置內容的最大高度

scalePhotos

true

If 'true' and if maxWidth, maxHeight, innerWidth, innerHeight, width, or height have been defined, ColorBox will scale photos to fit within the those values.
如果是true且maxWidth, maxHeight, innerWidth, innerHeight, width, 或者 height 被設置,Colorbox會縮放圖片以使用邊框

scrolling

true

If 'false' ColorBox will hide scrollbars for overflowing content. This could be used on conjunction with the resize method (see below) for a smoother transition if you are appending content to an already open instance of ColorBox.
如果是false,Colorbox不會為了溢出元素設置滾動條

iframe

false

If 'true' specifies that content should be displayed in an iFrame.
如果是true,元素會在Iframe中顯示

inline

false

If 'true' a jQuery selector can be used to display content from the current page. Example: $("#inline").colorbox({inline:true, href:"#myForm"});
如果是true,jQuery選擇器可以用來選擇要顯示的元素。例如:

html

false

This allows an HTML string to be used directly instead of pulling content from another source (ajax, inline, or iframe). Example: $.fn.colorbox({html:'<p>Hello</p>'});
這個是直接讓你顯示HTML代碼,例如:

photo

false

If true, this setting forces ColorBox to display a link as a photo. Use this when automatic photo detection fails (such as using a url like 'photo.php' instead of 'photo.jpg', 'photo.jpg#1', or 'photo.jpg?pic=1')
如果為true,ColorBox只會把元素按照圖片顯示,防止類似photo.php?pic=1這樣的連接被誤認為是網頁

opacity

0.85

The overlay opacity level. Range: 0 to 1.
遮罩層不透明度 從0-1之間取值

open

false

If true, the lightbox will automatically open with no input from the visitor.
如果為true,ColorBox會自動開啟

preloading

true

Allows for preloading of 'Next' and 'Previous' content in a shared relation group (same values for the 'rel' attribute), after the current content has finished loading. Set to 'false' to disable.
如果為True,ColorBox會自動預載要顯示圖片

overlayClose

true

If true, enables closing ColorBox by clicking on the background overlay.
為true單擊遮罩層就可以把ColorBox關閉

slideshow

false

If true, adds an automatic slideshow to a content group / gallery.
為True,會自動滾動圖片

slideshowSpeed

2500

Sets the speed of the slideshow, in milliseconds.
設置時間,毫秒

slideshowAuto

true

If true, the slideshow will automatically start to play.
為tuue,滑動會自動開始

slideshowStart

"start slideshow"

Text for the slideshow start button.
開始自動滑動按鈕的文本

slideshowStop

"stop slideshow"

Text for the slideshow stop button
停止自動滑動按鈕的文本

current

"{current} of {total}"

Text format for the content group / gallery count. {current} and {total} are detected and replaced with actual numbers while ColorBox runs.
文本內容:現在正在顯示的元素序號,格式"{現在} of {總計}"

previous

"previous"

Text for the previous button in a shared relation group (same values for 'rel' attribute).
“上一個”按鈕的文本

next

"next"

Text for the next button in a shared relation group (same values for 'rel' attribute).
“下一個”按鈕的文本

close

"close"

Text for the close button. The 'Esc' key will also close ColorBox.
“關閉”按鈕的文本

onOpen

false

Callback that fires right before ColorBox begins to open.
下面幾個都是在XXX時候要執行的函數,不用多說,一看就會

onLoad

false

Callback that fires right before attempting to load the target content.

onComplete

false

Callback that fires right after loaded content is displayed.

onCleanup

false

Callback that fires at the start of the close process.

onClosed

false

Callback that fires once ColorBox is closed.

下面幾個方法由于時間問題沒能來得及翻譯,有空一定為大家補上
Public Methods
$.fn.colorbox()This method allows you to call ColorBox without having to assign it to an element. Returns 'this' (document). Example: $.fn.colorbox({href:'login.php', open:true});
$.fn.colorbox.next() & $.fn.colorbox.prev()These methods moves to the next and previous items in a gallery and are the same as pressing the 'next' or 'previous' buttons. Returns nothing.
$.fn.colorbox.close()This method initiates the close sequence, which does not immediately complete. The lightbox will be completely closed only when the 'cbox_closed' event is fired. Returns nothing.
$.fn.colorbox.element()This method is used to fetch the current HTML element that ColorBox is associated with. Returns a DOM element. Example: var that = $.fn.colorbox.element();
$.fn.colorbox.resize()This allows ColorBox to auto-resize it's height if it's content is altered. This must be called manually after the content has been updated. Set 'scrollbars' to false to prevent them from being displayed during the resize animation.
$.fn.colorbox.init()This runs silently when the DOM is first loaded and is used to initialize the lightbox (adds necessary HTML to the DOM, preloads the interface graphics, initializes variables, etc). If ColorBox were completely removed from the DOM, to load in a new stylesheet for example, this would be needed to re-initialize it.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,563評論 6 544
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,694評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,672評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,965評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,690評論 6 413
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 56,019評論 1 329
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,013評論 3 449
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,188評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,718評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,438評論 3 360
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,667評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,149評論 5 365
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,845評論 3 351
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,252評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,590評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,384評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,635評論 2 380

推薦閱讀更多精彩內容