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

  1. ThomasAleve表示:

    Discover Casper Ruud’s https://tennis.casper-ruud-fr.com journey from his Challenger debut to the top 10 of the world tennis rankings. A unique success.

  2. CarlosShapy表示:

    The fascinating story of Alexander Zverev’s https://tennis.alexander-zverev-fr.biz rapid rise from a junior star to one of the leaders of modern tennis.

  3. DennyPax表示:

    The fascinating story of Daniil Medvedev’s https://tennis.daniil-medvedev-fr.biz rise to world number one. Find out how a Russian tennis player quickly broke into the elite and conquered the tennis Olympus.

  4. RandyHak表示:

    Carlos Alcaraz https://tennis.carlos-alcaraz-fr.biz from a talented junior to the ATP top 10. His rise is the result of hard work, support and impressive victories at major world tournaments.

  5. Haroldfug表示:

    Jannik Sinner https://tennis.jannik-sinner-fr.biz an Italian tennis player, went from starting his career to entering the top 10 of the ATP, demonstrating unique abilities and ambitions in world tennis.

  6. En guvenilir online casino Sweet bonanza

  7. Uazrqmo表示:

    Добрый день!
    Приобрести диплом любого университета
    Наша компания предлагает выгодно заказать диплом, который выполнен на оригинальном бланке и заверен печатями, штампами, подписями должностных лиц. Наш документ пройдет любые проверки, даже с использованием специфических приборов. Достигайте своих целей быстро и просто с нашими дипломами.
    Где заказать диплом по нужной специальности?
    http://androidinweb.ru/kupite-diplom-i-poluchite-novyie-vozmozhnosti
    Будем рады вам помочь!.

  8. En populer kumarhaneyi deneyin Sweet bonanza

  9. Uazrrkv表示:

    Здравствуйте!
    Приобрести диплом любого ВУЗа
    Наши специалисты предлагают выгодно купить диплом, который выполнен на бланке ГОЗНАКа и заверен печатями, водяными знаками, подписями должностных лиц. Наш документ пройдет лубую проверку, даже с применением специфических приборов. Достигайте своих целей быстро и просто с нашей компанией.
    Где купить диплом по необходимой специальности?
    http://lapd.getbb.ru/viewtopic.php?f=5&t=443
    Всегда вам поможем!.

  10. Dmanbq表示:

    brand minoxidil – buy dutas for sale buy finpecia

  11. ClaudeInhab表示:

    Find out the story of Jon Jones https://ufc.jon-jones-fr.biz in the UFC: his triumphs, records and controversies, which made him one of the greatest fighters in the MMA world.

  12. Brucemap表示:

    The story of the great Kobe Bryant https://los-angeles-lakers.kobe-bryant-fr.com with ” Los Angeles Lakers: his path to the championship, his legendary achievements.

  13. WilliamCen表示:

    Novak Djokovic’s https://tennis.novak-djokovic-fr.biz journey from childhood to the top of world tennis: early years, first victories, dominance and influence on the sport.

  14. BrianCaf表示:

    The success story of the French footballer https://juventus.thierry-henry.biz at Juventus: from his career at the club to leadership on the field , becoming a legend and a source of inspiration for youth.

  15. Thomasswady表示:

    Del Mar Energy Inc is an international industrial holding company engaged in the extraction of oil, gas, and coal

  16. Thomasswady表示:

    Del Mar Energy Company is an international industrial holding company engaged in the extraction of oil, gas, and coal

  17. Guvenilir bir kumarhanede sans?n?z Sweet bonanza

  18. ZacharyChalk表示:

    Golden State Warriors success story https://golden-state-warriors.stephen-curry-fr.com Stephen Curry: From becoming a leader to creating a basketball dynasty that redefined the game.

  19. Anthonyshund表示:

    The history of Michael Jordan’s Chicago Bulls https://chicago-bulls.michael-jordan-fr.com extends from his rookie in 1984 to a six-time NBA championship.

  20. Donaldror表示:

    Victor Wembanyama’s travel postcard https://san-antonio-spurs.victor-wembanyama.biz from his career in France to his impact in the NBA with the San Antonio Spurs.

  21. StanleyCit表示:

    Neymar https://al-hilal.neymar-fr.com at Al-Hilal: his professionalism and talent inspire young people players, taking the club to new heights in Asian football.

  22. Rodgersam表示:

    The story of the Moroccan footballer https://al-hilal.yassine-bounou.com, who became a star at Al-Hilal, traces his journey from the streets of Casablanca to international football stardom and his personal development.

  23. Bu kumarhanedeki en iyi oyunlar Sweet bonanza

  24. JamesDup表示:

    Leroy Sane’s https://bavaria.leroy-sane-ft.com success story at FC Bayern Munich: from adaptation to influence on the club’s results. Inspiration for hard work and professionalism in football.

  25. Jeffreyacupe表示:

    Discover the story of Rudy Gobert https://minnesota-timberwolves.rudy-gobert.biz, the French basketball player whose defensive play and leadership transformed the Minnesota Timberwolves into a powerhouse NBA team.

  26. JamesFus表示:

    From childhood teams to championship victories, the path to success with the Los Angeles Lakers https://los-angeles-lakers.lebron-james-fr.com requires not only talent, but also undeniable dedication and work.

  27. WilliambiX表示:

    Discover Pierre Gasly’s https://alpine.pierre-gasly.com journey through the world of Formula 1, from his beginnings with Toro Rosso to his extraordinary achievements with Alpine.

  28. HenryReurl表示:

    Discover the journey of Charles Leclerc https://ferrari.charles-leclerc-fr.com, from young Monegasque driver to Ferrari Formula 1 leader, from his early years to his main achievements within the team.

發佈留言

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