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

  1. Eddiehem表示:

    In the world of professional tennis, the name of Gustavo Kuerten https://roland-garros.gustavokuerten.com is closely linked to one of the most prestigious Grand Slam tournaments – Roland Garros.

  2. MichaelHycle表示:

    Ayrton Senna https://mclaren.ayrtonsenna-br.com is one of the greatest drivers in the history of Formula 1.

  3. Darrellspoop表示:

    Bieber’s https://baby.justinbieber-br.com path to global fame began with his breakthrough success Baby, which became his signature song and one of the most popular music videos of all time.

  4. Gilbertmax表示:

    Achraf Hakimi https://paris-saint-germain.ashrafhakimi.net is a young Moroccan footballer who quickly reached the football elite European in recent years.

  5. ErnestWeask表示:

    Kobe Bryant https://los-angeles-lakers.kobebryant-br.net one of the greatest basketball players of all the times, left an indelible mark on the history of sport.

  6. Kumar oynamak icin en iyi secim Sweet bonanza

  7. Sqlkzv表示:

    buy atenolol pills for sale – coreg us carvedilol 6.25mg without prescription

  8. as I am confident they will continue to enrich the discourse on [specific topic].”Your article on [specific topic] provided a truly holistic view that was both comprehensive and enlightening.ラブドール

  9. Technological improvements have grown to be centralオナドール in all aspects of our lives, including the subject of sexuality.

  10. Sizin icin harika bir kumarhane Sweet bonanza

  11. LarryLep表示:

    Selena Gomez https://calm-down.selenagomez-br.net the story from child star to global musical influence, summarized in hit “Calm Down”, with Rema.

  12. with lifelike skin texture and intricately crafted facial features that make it look incredibly real.ラブドール 中古The customization process on com was straightforward and enjoyable,

  13. Williamraimb表示:

    Fabrizio Moretti https://the-strokes.fabriziomoretti-br.com the influential drummer of The Strokes, and his unique sound revolutionized the music scene, remaining icons of modern rock.

  14. Robertpruff表示:

    The rise of 20-year-old midfielder Jamal Musiala https://bavaria.jamalmusiala-br.com to the status of a winger in the Bayern Munich team. A story of incredible talent.

  15. BrandonNobia表示:

    A historia da jornada triunfante de Anitta https://veneno.anitta-br.com de aspirante a cantora a uma das interpretes mais influentes da musica moderna, incluindo sua participacao na serie de TV “Veneno”.

  16. Williamfob表示:

    In-depth articles about the most famous football players https://zenit-saint-petersburg.wendel-br.com, clubs and events. Learn everything about tactics, rules of the game and football history.

  17. Carloshiedo表示:

    The incredible story https://napoli.khvichakvaratskhelia-br.com of a young Georgian talent’s transformation into an Italian Serie A star. Khvicha Kvaraeshvili is a rising phenomenon in European football.

  18. JustinVom表示:

    Midfielder Rafael Veiga leads https://manchester-city.philfoden-br.com Palmeiras to success – the championship Brazilian and victory in the Copa Libertadores at the age of 24.

  19. CharlesFlalf表示:

    O meio-campista Rafael Veiga leva https://palmeiras.raphaelveiga-br.com o Palmeiras ao sucesso – o campeonato brasileiro e a vitoria na Copa Libertadores aos 24 anos.

  20. DonaldEmumn表示:

    The compelling story of Alisson Becker’s https://bayer-04.florianwirtz-br.com meteoric rise from young talent to key figure in Liverpool’s triumphant era under Jurgen Klopp.

  21. Williamfed表示:

    The incredible success story of 20-year-old Florian Wirtz https://bayer-04.florianwirtz-br.com, who quickly joined the Bayer team and became one of the best young talents in the world.

  22. Jesussaw表示:

    Ousmane Dembele’s https://paris-saint-germain.ousmanedembele-br.com rise from promising talent to key player for French football giants Paris Saint-Germain. An exciting success story.

  23. Chuckcug表示:

    Лучшие пансионаты для пожилых людей https://ernst-neizvestniy.ru в Самаре – недорогие дома для престарелых в Самарской области

  24. Charlesror表示:

    The fascinating story of Sergio Ramos’ https://seville.sergioramos.net rise from Sevilla graduate to one of Real Madrid and Spain’s greatest defenders.

  25. Williammof表示:

    Пансионаты для пожилых людей https://moyomesto.ru в Самаре по доступным ценам. Специальные условия по уходу, индивидуальные программы.

  26. Dvehue表示:

    calan online – order valsartan 160mg pills buy tenoretic no prescription

  27. Ronnieedusa表示:

    Хотите научиться готовить самые изысканные и сложные торты? В этом https://v1.skladchik.org/tags/tort/ разделе вы найдете множество подробных пошаговых рецептов самых трендовых и известных тортов с возможностью получить их за сущие копейки благодаря складчине. Готовьте с удовольствием и открывайте для себя новые рецепты вместе с Skladchik.org

  28. MauriceChose表示:

    сайт драгон мани казино онлайн казино Dragon Money

發佈留言

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