jQuery Plugin – LightBox2

這篇文章也在馬老師舊的部落格出現過,不過既然搬家了就重新做一次吧!其實在馬老師雲端研究室裡面也大量應用了這樣的效果,無論你在這點選了圖片或Flash都會觸發這個效果,相信大家也看過很多次了,接下來我們就看看怎麼樣在自己的網頁中加入這樣的效果,首先大家可以先到LightBox2的官方網站下載他們打包好的jQuery和CSS…等資源,或按我直接下載。

LightBox2 範例圖1

下載後會有以下三個資料夾比較重要:

LightBox2 範例圖2
  • CSS資料夾是放LightBox2所需要用到的CSS樣式表
  • images資料夾是放LightBox2所需要用到的圖檔(例如上一張、下一張的按鈕)
  • js資料夾是放LightBox2所需要用到的jQuery檔

接下來就可以開始製作網頁,在製作前也需要先準備一些大圖和小圖,如下圖例:

LightBox2 範例圖3

範例中檔名有s的表示縮圖(160×120)、另外就是大圖(640×480),在網頁裡面首先置入縮圖,在縮圖上製作超連結到大圖。

LightBox2 範例圖4

接下來就要開始針對語法做些處理了,在HTML中<head>…</head>區段加入以下的程式碼:

<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />

第1~3行是連結LightBox2中jQuery的程式,第4行則是連結LightBox2中CSS的樣式表,再來處理超連結的語法,在原本製作圖片超連結的部份加入rel=”lightbox[g1]”的語法,如下:

<a href="foods/location_pic_1.jpg" rel="lightbox[g1]"><img src="foods/location_pic_1_s.jpg" width="160" height="120" border="0" /></a> 
<a href="foods/location_pic_2.jpg" rel="lightbox[g1]"><img src="foods/location_pic_2_s.jpg" width="160" height="120" border="0" /></a> 
<a href="foods/location_pic_3.jpg" rel="lightbox[g1]"><img src="foods/location_pic_3_s.jpg" width="160" height="120" border="0" /></a>

其中g1的部份是表示這個圖片的群組,如果三張圖片都是g1則點選任一張,都可以在畫面中切換看到這三張,但若兩張圖片是g1第三張是g2的話,點選第一張圖片後只能切換到第二張,第三張則為獨立的圖檔,大家可以依照自己的情形修改括號內的文字,整體製作好的網頁語法如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LightBox2</title>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
</head>

<body>
<a href="foods/location_pic_1.jpg" rel="lightbox[g1]"><img src="foods/location_pic_1_s.jpg" width="160" height="120" border="0" /></a> 
<a href="foods/location_pic_2.jpg" rel="lightbox[g1]"><img src="foods/location_pic_2_s.jpg" width="160" height="120" border="0" /></a> 
<a href="foods/location_pic_3.jpg" rel="lightbox[g1]"><img src="foods/location_pic_3_s.jpg" width="160" height="120" border="0" /></a>
</body>
</html>

在這邊也提供整個製作完成的範例讓大家下載參考,或直接觀賞網頁檔,其實這個範例還有一些額外的小東西可以改,比如說彈出視窗的圖片標題,按鈕中文化…等,還要請大家再多多研究一下囉!希望這個範例對大家有所幫助,如果還有疑問,也可以在這邊回應唷~

You may also like...

15,118 Responses

  1. гадание на индийском пасьянсе http://indiyskiy-pasyans-online.ru/ .

  2. Great site! I recommend it to everyone!Book private flights

  3. The commitment to customer happiness is evident not only in the physical attributes of the doll but also オナニー ドールin the comprehensive service and support offered throughout the ownership journey.

  4. Great site! I recommend it to everyone!Private jet empty legs

  5. Tkmczi表示:

    purchase imusporin – buy colcrys generic gloperba uk

  6. For example, a person who has a high sex drive may use a sex dollセックス ボット as a way to meet their needs without putting additional pressure on their significant other.

  7. Lewisslund表示:

    Начните играть в Sugar Rush и получайте настоящие выигрыши, sugar rush с крупными выигрышами

  8. Great site! I recommend it to everyone!Private jet charter

  9. продвижение сайтов в москве тарифы http://www.prodvizhenie-sajtov-v-moskve119.ru .

  10. Отличный сайт! Всем рекомендую!справочник

  11. продвижение сайтов интернет магазины в москве продвижение сайтов интернет магазины в москве .

  12. Цена установки кондиционера в Липецке http://ustanovka-kondicionerov480.ru/ .

  13. Виза цифрового кочевника в Испании https://klaipedatours.ru .

  14. Lewisslund表示:

    Wonderful, what a weblog it is! This web site provides helpful data to us, keep it up.

    https://vodamarket.od.ua/idealne-sklo-dlya-far-vybir-ta-vstanovlennya

  15. Ismaelfer表示:

    This is my first time go to see at here and i am really impressed to read all at alone place.

    отделка

  16. Отличный сайт! Всем рекомендую!справочник

  17. Timsothyabela表示:

    This text is priceless. Where can I find out more?
    gama казино

  18. service that will transport your car across country http://www.Car-shipping24.com .

  19. Отличный сайт! Всем рекомендую!каталог сайтов

  20. Отличный сайт! Всем рекомендую!рейтинг сайтов

  21. технический аудит сайта заказать http://www.prodvizhenie-sajtov15.ru .

  22. ラブドール エロpower/control,and attempts to achieve or perform masculinity.

  23. Отличный сайт! Всем рекомендую!пиастрикс казино

  24. エロ 人形表示:

    ” Love is always there.えろ 人形Praise comes and goes.

  25. Twatct表示:

    cheap trileptal – pirfenidone medication order levothyroxine generic

  26. and this is the closest you’ve been emotionally in years,ラブドール 高級 it would make sense why your body responds to that and wants to be more intimat”For many couples,

  27. エロ 人形表示:

    えろ 人形These experiences leave psychic scars,most commonly in the form of emotional reactions that try to protect you from ever feeling that kind of pain again—or from ever risking being attacked or shunned.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。