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

  1. porno_gvEi表示:

    русский анал смотреть бесплатно русский анал смотреть бесплатно .

  2. RonnieBib表示:

    Открытие для себя Ерлинг Хааланда https://manchestercity.erling-haaland-cz.com, a talented player of «Manchester City». Learn more about his skills, achievements and career growth.

  3. где купить dolce gabbana http://www.scm-fashion.ru .

  4. где купить dolce gabbana http://www.scm-fashion.ru .

  5. Где купить Дольче Габбана http://scm-fashion.ru .

  6. Brandonadalp表示:

    News, tournaments, guides and strategies about the latest GTA games https://gta-ar.com. Stay tuned for the best GTA gaming experience

  7. Robertphoff表示:

    Latest news https://android-games-ar.com about Android games, reviews and daily updates. The latest information about the most exciting games.

  8. Williamknome表示:

    Discover the wonderful world of online games https://game-news-ar.com. Get the latest news, reviews and tips for your favorite games.

  9. FelixThoks表示:

    Minecraft news https://minecraft-ar.com, guides and in-depth reviews of the gaming features available in Minecraft Ar. Get the latest information on downloading Minecraft, Pocket Edition and Bedrock Edition.

  10. Pqqfkh表示:

    buy generic ascorbic acid – purchase ascorbic acid generic cost prochlorperazine

  11. RichardAcure表示:

    News and events of the American Basketball League https://basketball-eg.com in Egypt. Hot events, player transfers and the most interesting events. Explore the world of the NBA with us.

  12. Ronaldmup表示:

    The most important sports news https://bein-sport-egypt.com, photos and blogs from experts and famous athletes, as well as statistics and information about matches of leading leagues.

  13. KermitAllow表示:

    UFC news https://ufc-ar.com, schedule of fights and tournaments 2024, ratings of UFC fighters, interviews, photos and videos. Live broadcasts and broadcasts of tournaments, statistics, forums and fan blogs.

  14. Jasonfew表示:

    NHL news https://nhl-ar.com (National Hockey League) – the latest and most up-to-date NHL news for today.

  15. Patrickwek表示:

    Интернет магазин электроники и цифровой техники по доступным ценам. Доставка мобильной электроники по Москве и Московской области.

  16. Great site! I recommend to everyone!The best hotels

  17. Albertotar表示:

    Discover the dynamic world of Arab sports https://sports-ar.com through the lens of Arab sports news. Your premier source for breaking news, exclusive interviews, in-depth analysis and live coverage of everything happening in sports.

  18. LewisCaume表示:

    Spider-Man https://spiderman.kz the latest news, articles, reviews, dates, spoilers and other latest information. All materials on the topic “Spider-Man”

  19. Staceykek表示:

    Latest Counter-Strike 2 news https://counter-strike-kz.kz, watch the most successful tournaments and be the best in the gaming world.

  20. HerbertWix表示:

    The latest top football news https://football.sport-news-eg.com today. Interviews with football players, online broadcasts and match results, analytics and football forecasts, photos and videos.

  21. En guvenilir kumarhanede kazan?n Sweet bonanza

  22. Help you get the most out of the services – Promonode

  23. Ujiqmy表示:

    buy generic ondansetron 4mg – order eldepryl pills where to buy requip without a prescription

  24. Seveceginiz bir online casino Sweet bonanza

  25. MichaelTiP表示:

    Зеркала интерьерные https://zerkala-mag.ru в интернет-магазине «Зеркала с подсветкой» Самые низкие цены на зеркала!

  26. JamesEluck表示:

    Предлагаем купить гаражное оборудование https://profcomplex.pro, автохимию, технику и уборочный инвентарь для клининговых компаний. Доставка по Москве и другим городам России.

  27. Thomasvamum表示:

    Доставка груза и грузоперевозки https://tamozhennyy-deklarant.blogspot.com по России через транспортную компанию автотранспортом доступна и для частных лиц. Перевозчик отправит или доставит ваш груз: выгодные тарифы индивидуальный подход из рук в руки 1 машиной.

  28. BrettMuh表示:

    Latest news and analysis of the Premier League https://premier-league.kz. Full descriptions of matches, team statistics and the most interesting football events. Premier Kazakhstan is the best place for football fans.

  29. Kumar oynamak icin en iyi secim Sweet bonanza

  30. LeslieScake表示:

    Latest news about games for Android https://android-games.kz, reviews and daily updates. Read now and get the latest information about the most exciting games

發佈留言

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