Jquery彈出層外掛程式ThickBox的使用方法,jquerythickbox

來源:互聯網
上載者:User

Jquery彈出層外掛程式ThickBox的使用方法,jquerythickbox

thickbox是jQuery的一個外掛程式,其作用是彈出對話方塊、網頁框,使使用者體驗度更加愉悅,下面就來簡單介紹它的幾種用法。
聲明一下:這隻是個人的總結記載而已。
準備工作:你需要三個檔案:thickbox.js、thickbox.css、jquery.js,網上到處可下

具體使用:

第一步:將這三個檔案引入到你要使用thickbox的頁面

複製代碼 代碼如下:
<script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="thickbox.js"></script>
    <link rel="stylesheet" href="thickbox.css" type="text/css" />

第二步:一般簡單使用就是給<a>標籤和Button添加樣式:class=thickbox
還有就是通過thickbox函數調用:如tb_init()、tb_show();見下文。

幾種不同用法:

1.點擊顯示圖片:

 <a href="001.jpg" class="thickbox"><img src="001.jpg"/></a>
ok,就這樣搞定
2.點擊按鈕或連結:

複製代碼 代碼如下:
<input alt="#TB_inline?height=300&width=400&inlineId=div1" title="shawnliu" class="thickbox" type="button" value="Show" />  
   <a href="#TB_inline?height=155&width=300&inlineId=div2&modal=true" class="thickbox">Show hidden modal content.</a>
  
   <div id="div1" style="display:none">
   <P>
     這是一個非強制回應對話方塊。
   </P>
   </div>

   <div id="div2" style="display:none">
   <P>
     這是一個強制回應對話方塊。
     <p style="TEXT-ALIGN: center"><INPUT id="Login" onclick="tb_remove()" type="submit" value="  Ok  " /></p>
   </P>
   </div>

說明:給你要使用thickbox的<a>或button添加"#TB_inline?height=300&width=400&",#TB_inline是thickbox固定用法,height和width是顯示彈出對話方塊的大小參數,inlineId是你要顯示的標籤或組件,modal是模式與非強制回應選擇,當然你還可以接很多你自訂的參數
3.一般在項目中用得比較多的就是載入form的頁面,如添加,編輯在同一個list列表頁面,這時我們就可以將添加和編輯都做成thickbox形式,如:

怎樣做呢一樣的,給添加連結加thickbox樣式:

<a href="add.shtml?width=300&height=250" class="thickbox">新增</a>
前提是你得將要顯示的頁面(add.shtml)做好,然後指定你要顯示的大小
編輯同樣是一樣:先將原資訊提取出來,再讓使用者修改:

代碼也一樣:

複製代碼 代碼如下:
<a href="edit.shtml?width=300&height=250&nid=item.nid" class="thickbox">編輯</a>

4.能自己定位到需要用thickbox的元素,不使用樣式,可以用函數,如:

複製代碼 代碼如下:
<div id="PicList">
<a href="Pic01.jpg"><img src="Pic01s.jpg" border="0"/></a>
<a href="Pic02.jpg"><img src="Pic01s.jpg" border="0"/></a>
</div>

$(function() {
tb_init("#PicList a[img]");});

5.通過ajax載入的頁面,thickbox樣式會失效,解決辦法:
只要在AJAX載入HTML並更新到頁面後執行下以下代碼:

tb_init('.thickbox');
6.自訂函數調用:
如點擊縮圖,要顯示大圖,縮圖URL只不過在大圖URL的尾碼前加了s:

複製代碼 代碼如下:
<div id="PicList">
<img src="Pic01s.jpg" border="0"/>
<img src="Pic01s.jpg" border="0"/>
</div>

$(function() {
$("#PicList img").click(function() {
tb_show("",this.src.substring(0,this.src.length-5)+'.jpg',false);
});});

另外,如果想用其它事件,還可以將click改成你想觸發thickbox的事件。

THICKBOX支援一下瀏覽器:
Windows IE 6.0, Windows IE 7+, Windows FF 2.0.0.6+, Windows Opera 9.0+, Macintosh Safari 2.0.4+, Macintosh FF 2.0.0.6+, Macintosh Opera 9.10……但是據我的使用,IE6還是有點問題的!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.