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灯帮,下面是一個從網(wǎng)上找的一個中文的參考列表:
KEY
設(shè)置的值

DEFAULT
默認(rèn)值

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.
設(shè)置過渡效果的持續(xù)時間,毫秒

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”})
這個用來設(shè)置一個錨標(biāo)記的值或者一個不是錨的元素吁恍,例如圖像或者表單的按鈕冀瓦,例如:

title

false

This can be used as an anchor title alternative for ColorBox.
這可以為Colorbox設(shè)置一個標(biāo)題

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′})
這個可以根據(jù)元素的rel屬性設(shè)置要顯示的元素集合翼闽,也可以覆蓋一個存在的rel屬性

width

false

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

height

false

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

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
這個可以設(shè)定一個固定的內(nèi)大小狂巢,包括邊框和按鈕

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
這個可以設(shè)定一個固定的內(nèi)高度,包括邊框和按鈕

initialWidth

300

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

initialHeight

100

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

maxWidth

false

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

maxHeight

false

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

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 被設(shè)置,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不會為了溢出元素設(shè)置滾動條

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這樣的連接被誤認(rèn)為是網(wǎng)頁

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會自動預(yù)載要顯示圖片

overlayClose

true

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

slideshow

false

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

slideshowSpeed

2500

Sets the speed of the slideshow, in milliseconds.
設(shè)置時間,毫秒

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.
文本內(nèi)容:現(xiàn)在正在顯示的元素序號甚疟,格式”{現(xiàn)在} 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.
“關(guān)閉”按鈕的文本

onOpen

false

Callback that fires right before ColorBox begins to open.
下面幾個都是在XXX時候要執(zhí)行的函數(shù)览妖,不用多說黄痪,一看就會

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.

上面列表轉(zhuǎn)載自:http://hi.baidu.com/234000/

(原創(chuàng))關(guān)于一款優(yōu)秀的Jquery插件-Colorbox的官方用法翻譯
2010年01月17日 星期日 11:13
原創(chuàng)文章盔然,如果您需要轉(zhuǎn)載愈案,請您注明來源來自 http://hi.baidu.com/234000/ 謝謝站绪!
Colorbox:http://colorpowered.com/colorbox/
Colorbox是一個能在你的瀏覽器窗口中創(chuàng)建一個模態(tài)對話框的程序丽柿。甫题。。也就是類似大家經(jīng)趁舫粒看到的那種遮罩層+提示框的樣子盟迟。當(dāng)然潦闲,你也可以讓遮罩層不顯示的歉闰。
在以前卓起,用于Jquery的類似插件應(yīng)該毫無疑問是Thickbox既绩。不過前一陣子去Jquery Plugins看的時候發(fā)現(xiàn)Thickbox已經(jīng)停止了更新还惠,且Jquery官方推薦了幾個Thickbox的替代品蚕键,我最終選擇了Colorbox,因為它十分的簡單易用和強大笆怠。
以下是Colorbox的官方介紹翻譯蹬刷,希望對大家有所幫助频丘。
——————————————————————————————————————————
Colorbox
Jquery的一個輕量的搂漠,可自定義的 lightbox 插件桐汤。
為什么選擇Colorbox?
Supports photos, photo groups, slideshow, ajax, inline, and iframed content.
支持圖片,圖片組员萍,圖片滑動觀看充活,ajax,行內(nèi)元素和iframe內(nèi)容

· 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的行為設(shè)置而不用改ColorBox的js文件
· Can be extended with callbacks & event-hooks without altering the source files.
· 可以直接加上回調(diào)函數(shù)和事件鉤子而不用更改它的源代碼
· Completely unobtrusive, options are set in the JS and require no changes to existing HTML.
· 非入侵式操作窖张,選項可以在JS中設(shè)置而不用更改HTML
· Preloads background images and can preload upcoming images in a photo group.
· 可以預(yù)載背景圖片和圖片組中的圖片
· Written in jQuery plugin format and can be chained with other jQuery commands.
· 用Jquery插件格式編寫宿接,可以使用鏈?zhǔn)讲僮?br> · Generates W3C valid XHTML and adds no JS global variables & passes JSLint.
· 語法通過W3C和XHTML認(rèn)證,沒有添加JS的全局變量
· Released under the MIT License.
· 在 MIT License下發(fā)布
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()函數(shù)使用一堆key/value對象和一個可選的callback函數(shù)
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
設(shè)置的值

Default
默認(rèn)值

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.
設(shè)置過渡效果的持續(xù)時間塞绿,毫秒

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"})
這個用來設(shè)置一個錨標(biāo)記的值或者一個不是錨的元素恤批,例如圖像或者表單的按鈕喜庞,例如:

title

false

This can be used as an anchor title alternative for ColorBox.
這可以為Colorbox設(shè)置一個標(biāo)題

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'})
這個可以根據(jù)元素的rel屬性設(shè)置要顯示的元素集合延都,也可以覆蓋一個存在的rel屬性

width

false

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

height

false

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

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
這個可以設(shè)定一個固定的內(nèi)大小嫉你,包括邊框和按鈕

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
這個可以設(shè)定一個固定的內(nèi)高度幽污,包括邊框和按鈕

initialWidth

300

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

initialHeight

100

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

maxWidth

false

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

maxHeight

false

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

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 被設(shè)置距误,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不會為了溢出元素設(shè)置滾動條

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這樣的連接被誤認(rèn)為是網(wǎng)頁

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會自動預(yù)載要顯示圖片

overlayClose

true

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

slideshow

false

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

slideshowSpeed

2500

Sets the speed of the slideshow, in milliseconds.
設(shè)置時間乘盖,毫秒

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.
文本內(nèi)容:現(xiàn)在正在顯示的元素序號兜叨,格式"{現(xiàn)在} 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.
“關(guān)閉”按鈕的文本

onOpen

false

Callback that fires right before ColorBox begins to open.
下面幾個都是在XXX時候要執(zhí)行的函數(shù)国旷,不用多說跪但,一看就會

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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末被环,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子浸锨,更是在濱河造成了極大的恐慌柱搜,老刑警劉巖剥险,帶你破解...
    沈念sama閱讀 206,311評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異匈庭,居然都是意外死亡阱持,警方通過查閱死者的電腦和手機魔熏,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,339評論 2 382
  • 文/潘曉璐 我一進店門蒜绽,熙熙樓的掌柜王于貴愁眉苦臉地迎上來躲雅,“玉大人,你說我怎么就攤上這事相寇』缴溃” “怎么了绵脯?”我有些...
    開封第一講書人閱讀 152,671評論 0 342
  • 文/不壞的土叔 我叫張陵蛆挫,是天一觀的道長。 經(jīng)常有香客問我楣导,道長,這世上最難降的妖魔是什么巴元? 我笑而不...
    開封第一講書人閱讀 55,252評論 1 279
  • 正文 為了忘掉前任逮刨,我火速辦了婚禮,結(jié)果婚禮上恢总,老公的妹妹穿的比我還像新娘片仿。我一直安慰自己尤辱,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 64,253評論 5 371
  • 文/花漫 我一把揭開白布光督。 她就那樣靜靜地躺著阳距,像睡著了一般。 火紅的嫁衣襯著肌膚如雪结借。 梳的紋絲不亂的頭發(fā)上筐摘,一...
    開封第一講書人閱讀 49,031評論 1 285
  • 那天,我揣著相機與錄音映跟,去河邊找鬼蓄拣。 笑死,一個胖子當(dāng)著我的面吹牛努隙,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播荸镊,決...
    沈念sama閱讀 38,340評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼咽斧,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了躬存?” 一聲冷哼從身側(cè)響起张惹,我...
    開封第一講書人閱讀 36,973評論 0 259
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎岭洲,沒想到半個月后宛逗,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,466評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡盾剩,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,937評論 2 323
  • 正文 我和宋清朗相戀三年雷激,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片告私。...
    茶點故事閱讀 38,039評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡屎暇,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出驻粟,到底是詐尸還是另有隱情根悼,我是刑警寧澤,帶...
    沈念sama閱讀 33,701評論 4 323
  • 正文 年R本政府宣布,位于F島的核電站挤巡,受9級特大地震影響剩彬,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜矿卑,卻給世界環(huán)境...
    茶點故事閱讀 39,254評論 3 307
  • 文/蒙蒙 一襟衰、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧粪摘,春花似錦瀑晒、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,259評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至椎咧,卻和暖如春玖详,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背勤讽。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評論 1 262
  • 我被黑心中介騙來泰國打工蟋座, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人脚牍。 一個月前我還...
    沈念sama閱讀 45,497評論 2 354
  • 正文 我出身青樓向臀,卻偏偏與公主長得像,于是被迫代替她去往敵國和親诸狭。 傳聞我的和親對象是個殘疾皇子券膀,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,786評論 2 345

推薦閱讀更多精彩內(nèi)容