Jquery ThickBox插件使用心得(不建議使用)
更新時(shí)間:2010年09月08日 09:30:17 作者:
最近發(fā)現(xiàn)一個(gè)不錯(cuò)的基于jquery的插件thickBox ,感覺比f(wàn)acebox好用。但因?yàn)閖query官方不推薦使用。所以這個(gè)只是學(xué)習(xí)的朋友,不建議使用這個(gè)。
大家可以使用官方推薦的一下幾個(gè)插件
While Thickbox had its day, it is not maintained any longer, so we recommend you use some alternatives.
* colorbox
* jQueryUI Dialog
* fancybox
* DOM window
* shadowbox.js
做項(xiàng)目中發(fā)現(xiàn)facebox如果快速單擊兩下,容易出現(xiàn)黑屏。而且facebox的框架是用table寫的,可能因?yàn)閠able相對(duì)div在結(jié)構(gòu)方面更穩(wěn)定些。如果彈出層里是table布局的,樣式就會(huì)受到facebox的樣式影響,還要重新reset一下。
看了下官方的api,我研究了下,做了個(gè)整理??聪聢D:

附件中index.html是主頁(yè),其它頁(yè)面都是調(diào)用頁(yè)面。點(diǎn)擊index頁(yè)面,就能看到如圖的頁(yè)面。圖、按鈕、文字都是可以點(diǎn)的。需要點(diǎn)擊的標(biāo)簽都要加上class="thickbox"。當(dāng)頁(yè)面出現(xiàn)滾動(dòng)條時(shí),彈出層固定在窗口的正中間不會(huì)移動(dòng)。當(dāng)彈出層中只是圖片時(shí),圖片大小會(huì)根據(jù)當(dāng)前窗口的大小進(jìn)行壓縮。所有的彈出層都可以按"esc"退出,除了需要點(diǎn)確認(rèn)的彈出層外,點(diǎn)擊彈出層以外的地方都可以關(guān)閉彈出層。
1.展示圖片(單張):
<a href="images/single.jpg" title="add a caption to title attribute / or leave blank" class="thickbox">
<img src="images/single.jpg" alt="Plant" width="100" height="75" />
</a>
2.展示圖片(多張):
<a href="images/plant1.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant1.jpg" alt="Plant 1" width="100" height="75"/>
</a>
<a href="images/plant2.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant2.jpg" alt="Plant 2" width="100" height="75"/>
</a>
<a href="images/plant3.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant3.jpg" alt="Plant 3" width="100" height="75"/>
</a>
<a href="images/plant4.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant4.jpg" alt="Plant 4" width="100" height="75"/>
</a>
這里每個(gè)a都要加上rel屬性,而且屬性值要一樣。前后展示圖可以通過" > "和" < "來切換
3.彈出層內(nèi)容在當(dāng)前頁(yè)面中時(shí):
<input alt="#TB_inline?height=150&width=400&inlineId=myOnPageContent" title="add a caption to title attribute / or leave blank" class="thickbox" value="Show" type="button">
the paragraph and input below in a ThickBox, or
<input alt="#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true" title="add a caption to title attribute / or leave blank" class="thickbox" value="Show hidden modal content" type="button">
<div id="myOnPageContent" style="display:none;">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p><select name=""><option>test</option></select></p>
</div>
<div id="hiddenModalContent" style="display:none;">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p style="text-align: center;"><input type="submit" onclick="tb_remove()" value=" Ok " id="Login"/></p>
</div>
第一個(gè)input點(diǎn)開的彈出層有input框、title和操作按鈕以及文字。第二個(gè)input點(diǎn)開的彈出層只有文字。
彈出層的大小是根據(jù)input的alt屬性里的width和height值來定義的。下面講到的幾種情況也是這樣來定義彈出層大小的。
4.調(diào)用外部文件,彈出層是iframe
<a href="ajaxFrame.PHP?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>
<a href="ajaxOverFlow2.html?keepThis=true&TB_iframe=true&height=300&width=500" title="add a caption to title attribute / or leave blank" class="thickbox">Example 2</a>
<a href="iframeModal.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true" title="add a caption to title attribute / or leave blank" class="thickbox">Open iFrame Modal</a>
如果彈出層是嵌套在iframe里需要添加“TB_iframe=true"。
第一個(gè)是調(diào)用ajaxFrame.PHP文件。
第二個(gè)是調(diào)用ajaxOverFlow2.html文件。
第三個(gè)是調(diào)用了iframeModal.html文件,隱藏了title和操作按鈕。
5.調(diào)用外部文件,彈出層不是iframe
<a href="ajaxOverFlow.html?height=300&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Scrolling content</a>
<a href="ajax.PHP?height=220&width=400" class="thickbox" title="add a caption to title attribute / or leave blank">No-scroll content</a>
<a href="ajaxLogin.html?height=85&width=250&modal=true" class="thickbox" title="Please Sign In">login (modal)</a>
<a href="ajaxTBcontent.html?height=200&width=300" class="thickbox" title="">Update ThickBox content</a>
第一個(gè)調(diào)用ajaxOverFlow.html文件。
第二個(gè)調(diào)用ajax.PHP文件。
第三個(gè)調(diào)用ajaxLogin.html文件,form表單。
第四個(gè)調(diào)用ajaxTBcontent.html文件,彈出層里再調(diào)用newTBcontent.html文件。
復(fù)制代碼 代碼如下:
While Thickbox had its day, it is not maintained any longer, so we recommend you use some alternatives.
* colorbox
* jQueryUI Dialog
* fancybox
* DOM window
* shadowbox.js
做項(xiàng)目中發(fā)現(xiàn)facebox如果快速單擊兩下,容易出現(xiàn)黑屏。而且facebox的框架是用table寫的,可能因?yàn)閠able相對(duì)div在結(jié)構(gòu)方面更穩(wěn)定些。如果彈出層里是table布局的,樣式就會(huì)受到facebox的樣式影響,還要重新reset一下。
看了下官方的api,我研究了下,做了個(gè)整理??聪聢D:

附件中index.html是主頁(yè),其它頁(yè)面都是調(diào)用頁(yè)面。點(diǎn)擊index頁(yè)面,就能看到如圖的頁(yè)面。圖、按鈕、文字都是可以點(diǎn)的。需要點(diǎn)擊的標(biāo)簽都要加上class="thickbox"。當(dāng)頁(yè)面出現(xiàn)滾動(dòng)條時(shí),彈出層固定在窗口的正中間不會(huì)移動(dòng)。當(dāng)彈出層中只是圖片時(shí),圖片大小會(huì)根據(jù)當(dāng)前窗口的大小進(jìn)行壓縮。所有的彈出層都可以按"esc"退出,除了需要點(diǎn)確認(rèn)的彈出層外,點(diǎn)擊彈出層以外的地方都可以關(guān)閉彈出層。
1.展示圖片(單張):
復(fù)制代碼 代碼如下:
<a href="images/single.jpg" title="add a caption to title attribute / or leave blank" class="thickbox">
<img src="images/single.jpg" alt="Plant" width="100" height="75" />
</a>
2.展示圖片(多張):
復(fù)制代碼 代碼如下:
<a href="images/plant1.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant1.jpg" alt="Plant 1" width="100" height="75"/>
</a>
<a href="images/plant2.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant2.jpg" alt="Plant 2" width="100" height="75"/>
</a>
<a href="images/plant3.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant3.jpg" alt="Plant 3" width="100" height="75"/>
</a>
<a href="images/plant4.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="flowers">
<img src="images/plant4.jpg" alt="Plant 4" width="100" height="75"/>
</a>
這里每個(gè)a都要加上rel屬性,而且屬性值要一樣。前后展示圖可以通過" > "和" < "來切換
3.彈出層內(nèi)容在當(dāng)前頁(yè)面中時(shí):
復(fù)制代碼 代碼如下:
<input alt="#TB_inline?height=150&width=400&inlineId=myOnPageContent" title="add a caption to title attribute / or leave blank" class="thickbox" value="Show" type="button">
the paragraph and input below in a ThickBox, or
<input alt="#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true" title="add a caption to title attribute / or leave blank" class="thickbox" value="Show hidden modal content" type="button">
<div id="myOnPageContent" style="display:none;">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p><select name=""><option>test</option></select></p>
</div>
<div id="hiddenModalContent" style="display:none;">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p style="text-align: center;"><input type="submit" onclick="tb_remove()" value=" Ok " id="Login"/></p>
</div>
第一個(gè)input點(diǎn)開的彈出層有input框、title和操作按鈕以及文字。第二個(gè)input點(diǎn)開的彈出層只有文字。
彈出層的大小是根據(jù)input的alt屬性里的width和height值來定義的。下面講到的幾種情況也是這樣來定義彈出層大小的。
4.調(diào)用外部文件,彈出層是iframe
復(fù)制代碼 代碼如下:
<a href="ajaxFrame.PHP?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>
<a href="ajaxOverFlow2.html?keepThis=true&TB_iframe=true&height=300&width=500" title="add a caption to title attribute / or leave blank" class="thickbox">Example 2</a>
<a href="iframeModal.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true" title="add a caption to title attribute / or leave blank" class="thickbox">Open iFrame Modal</a>
如果彈出層是嵌套在iframe里需要添加“TB_iframe=true"。
第一個(gè)是調(diào)用ajaxFrame.PHP文件。
第二個(gè)是調(diào)用ajaxOverFlow2.html文件。
第三個(gè)是調(diào)用了iframeModal.html文件,隱藏了title和操作按鈕。
5.調(diào)用外部文件,彈出層不是iframe
復(fù)制代碼 代碼如下:
<a href="ajaxOverFlow.html?height=300&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Scrolling content</a>
<a href="ajax.PHP?height=220&width=400" class="thickbox" title="add a caption to title attribute / or leave blank">No-scroll content</a>
<a href="ajaxLogin.html?height=85&width=250&modal=true" class="thickbox" title="Please Sign In">login (modal)</a>
<a href="ajaxTBcontent.html?height=200&width=300" class="thickbox" title="">Update ThickBox content</a>
第一個(gè)調(diào)用ajaxOverFlow.html文件。
第二個(gè)調(diào)用ajax.PHP文件。
第三個(gè)調(diào)用ajaxLogin.html文件,form表單。
第四個(gè)調(diào)用ajaxTBcontent.html文件,彈出層里再調(diào)用newTBcontent.html文件。
您可能感興趣的文章:
- 全面詳細(xì)的jQuery常見開發(fā)技巧手冊(cè)
- 60個(gè)很實(shí)用的jQuery代碼開發(fā)技巧收集
- 30個(gè)經(jīng)典的jQuery代碼開發(fā)技巧
- jQuery常見開發(fā)技巧詳細(xì)整理
- Web前端新人筆記之jquery入門心得(新手必看)
- jquery easyui使用心得
- jQuery Ajax使用心得詳細(xì)整理及注意事項(xiàng)
- 關(guān)于jQuery UI 使用心得及技巧
- php+jquery編碼方面的一些心得(utf-8 gb2312)
- 關(guān)于Jqzoom的使用心得 jquery放大鏡效果插件
- jQuery 使用個(gè)人心得
- jQuery 研究心得 取得屬性的值
- 15個(gè)值得開發(fā)人員關(guān)注的jQuery開發(fā)技巧和心得總結(jié)【經(jīng)典收藏】
相關(guān)文章
基于jQuery實(shí)現(xiàn)搜索關(guān)鍵字自動(dòng)匹配功能
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)搜索關(guān)鍵字自動(dòng)匹配功能,自動(dòng)匹配搜索關(guān)鍵詞功能廣泛應(yīng)用到搜索引擎當(dāng)中,感興趣的小伙伴們可以參考一下2015-10-10
基于Jquery實(shí)現(xiàn)鍵盤按鍵監(jiān)聽
本文介紹下,用jquery實(shí)現(xiàn)的滑動(dòng)效果,以及對(duì)鍵盤按鍵進(jìn)行監(jiān)聽的例子,有需要的朋友,可以參考學(xué)習(xí)下2014-05-05
JQUERY實(shí)現(xiàn)網(wǎng)頁(yè)右下角固定位置展開關(guān)閉特效的方法
這篇文章主要介紹了JQUERY實(shí)現(xiàn)網(wǎng)頁(yè)右下角固定位置展開關(guān)閉特效的方法,涉及jquery操作頁(yè)面元素的顯示與隱藏等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
Easyui在treegrid添加控件的實(shí)現(xiàn)方法
這篇文章主要介紹了Easyui在treegrid添加控件的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-06-06
jQuery將多條數(shù)據(jù)插入模態(tài)框的示例代碼
這篇文章主要介紹了使用jQuery將多條數(shù)據(jù)插入模態(tài)框的方法,很簡(jiǎn)單,很實(shí)用,需要的朋友可以參考下2014-09-09
jquery列表拖動(dòng)排列(由項(xiàng)目提取相當(dāng)好用)
最好的jquery列表拖動(dòng)排列自定義拖動(dòng)層排列。當(dāng)點(diǎn)擊或拖動(dòng)列表時(shí),可以自定義隨意拖放列表模塊到相應(yīng)位置2014-06-06

