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,120 Responses

  1. Toxmva表示:

    buy cheap generic besivance – besifloxacin eye drops sildamax for sale

  2. and easy to implement,ラブドールI have already started applying some of your suggestions,

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

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

  5. Предлагаем качественную печать на одежде для любого случая.

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

  7. hearing “no” without any opportunity to argue,ラブドール 中古persuade,

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

  9. Lewisslund表示:

    Hi there, its nice paragraph concerning media print, we all understand media is a fantastic source of facts.
    даркнет

  10. OLaneevige表示:

    Thanks for the auspicious writeup. It if truth be told was a amusement account it. Look advanced to far introduced agreeable from you! By the way, how can we keep up a correspondence?
    браузер тор

  11. Latest debates about sex dolls, sex robots, and personified sexual オナドールintercourse tech frame these products throughout the prospective for escalation and damage reduction

  12. AoolHesia表示:

    SOURCE: Reprinted with Permission from the National Brain Tumor FoundationGangliocytomaGangliocytomas, gangliomas, and anaplastic gangliogliomas are tumors that include neoplastic nerve cells that are relatively well differentiated.
    Customers satisfaction guarantee at ampicillin fungus is more convenient
    A person may feel anxious without having an anxiety disorder.

  13. Lewisslund表示:

    Hmm is anyone else encountering problems with the images on this blog loading? I’m trying to determine if its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.
    либет казино

  14. OLaneevige表示:

    For newest information you have to pay a visit world-wide-web and on the web I found this site as a best site for most up-to-date updates.
    lee bet

  15. Qshcfu表示:

    buy generic deflazacort – order deflazacort pills buy alphagan online cheap

  16. AujikHesia表示:

    Do I be careful or do I consider that it was all a scare which would wreck me but I dont have any other hope.
    Most online stores will guarantee you the glucophage solution at low prices, you’ll need to compare offers
    New York: HarperCollins, 2000.

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

  18. These dolls, previously viewed simply as tools for physical pleasure,ラブドール sexare now being pursued for more intricate and profound purposes.

  19. Wguuonert表示:

    Behavioral and other changes in fish and other animals — are usually associated with their exposure to endocrine disruptors and other chemicals.
    Begin saving money when you lyrica withdrawl do I need a prescription?
    Omega-3 fatty acids are recommended as a way to protect against heart disease and stroke.

  20. AxxzPaish表示:

    Thank you for your kind comment PurpleHubs.
    advisable to identify the best offers as soon as you decide to prednisone 20 mg tablet today
    That’s why it’s still important to visit a doctor and just make sure that you’re in good health.

  21. ラブドール おすすめpeople with ADHD often face additional challenges related to guilt and shame.In this post,

  22. The robots are coming,リアル エロbut probably not to replace our partners or upend our core desire to connect “Through layers of technology,

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

  24. Jxtiiu表示:

    lactulose online order – buy duphalac generic betahistine online

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

  26. продвижение сайтов в москве и московской области http://www.prodvizhenie-sajtov11.ru .

  27. seo оптимизация и продвижение сайтов москва http://www.prodvizhenie-sajtov11.ru .

  28. EarnestAvada表示:

    Hello there, You have done an excellent job. I will certainly digg it and personally recommend to my friends. I am confident they’ll be benefited from this web site.
    ispeakcity.ru

  29. индийский пасьянс гадать бесплатно http://www.indiyskiy-pasyans-online.ru .

發佈留言

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