jQuery Plugin – LightBox2
這篇文章也在馬老師舊的部落格出現過,不過既然搬家了就重新做一次吧!其實在馬老師雲端研究室裡面也大量應用了這樣的效果,無論你在這點選了圖片或Flash都會觸發這個效果,相信大家也看過很多次了,接下來我們就看看怎麼樣在自己的網頁中加入這樣的效果,首先大家可以先到LightBox2的官方網站下載他們打包好的jQuery和CSS…等資源,或按我直接下載。
下載後會有以下三個資料夾比較重要:
- CSS資料夾是放LightBox2所需要用到的CSS樣式表
- images資料夾是放LightBox2所需要用到的圖檔(例如上一張、下一張的按鈕)
- js資料夾是放LightBox2所需要用到的jQuery檔
接下來就可以開始製作網頁,在製作前也需要先準備一些大圖和小圖,如下圖例:
範例中檔名有s的表示縮圖(160×120)、另外就是大圖(640×480),在網頁裡面首先置入縮圖,在縮圖上製作超連結到大圖。
接下來就要開始針對語法做些處理了,在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>
在這邊也提供整個製作完成的範例讓大家下載參考,或直接觀賞網頁檔,其實這個範例還有一些額外的小東西可以改,比如說彈出視窗的圖片標題,按鈕中文化…等,還要請大家再多多研究一下囉!希望這個範例對大家有所幫助,如果還有疑問,也可以在這邊回應唷~
Guvenilir bir kumarhanede oynay?n Sweet bonanza
Gavi’s success story https://barcelona.gavi-fr.com at Barcelona: from his debut at 16 to a key role in club and national team of Spain, his talent inspires the world of football.
Analysis of Arsenal’s impressive revival https://arsenal.bukayo-saka.biz under the leadership of Mikel Arteta and the key role of young star Bukayo Saki in the club’s return to the top.
Pedri’s story https://barcelona.pedri-fr.com from his youth in the Canary Islands to becoming a world-class star in Barcelona, ??with international success and recognition.
Vinicius Junior https://vinicius-junior.org all the latest current and latest news for today about the player of the 2024 season
The best site dedicated to the football player Paul Pogba https://pogba.org. Latest news from the world of football.
If you are a fan of UFC https://ufc-hoje.com the most famous organization in the world, come visit us. The most important news and highlights from the UFC world await you on our website.
Site with the latest news, statistics, photos of Pele https://edson-arantes-do-nascimento.com and much more. Get the latest news and information about football legend Pele.
Welcome to our official website, where you will find everything about the career of Gianluigi Buffon https://gianluigi-buffon.org. Discover the story of this legendary goalkeeper who made football history.
The latest top football news https://futebol-ao-vivo.net today. Interviews with football players, online broadcasts and match results, analytics and football forecasts
A site dedicated to Michael Jordan https://michael-jordan.uz, a basketball legend and symbol of world sports culture. Here you will find highlights, career, family and news about one of the greatest athletes of all time.
купить диплом специалиста в казани ast-diplomy.com .
Get to know the history, players and latest news of the Inter Miami football club https://inter-miami.uz. Join us to learn about the successes and great performances of America’s newest and most exciting soccer club.
диплом южной осетии купить ast-diplomy.com .
Find the latest information on Conor McGregor https://conor-mcgregor.uz news, fights, and interviews. Check out detailed articles and news about McGregor’s UFC career, wins, training, and personal life.
Explore the dynamic world of sports https://noticias-esportivas-br.org through the lens of a sports reporter. Your source for breaking news, exclusive interviews, in-depth analysis and live coverage of all sports.
Discover how Riyad Mahrez https://al-ahli.riyad-mahrez.com transformed Al-Ahli, becoming a key player and catalyst in reaching new heights in world football.
Отличный сатй! Всем рекомендую!скупка золота москва
Latest news and information about Marcelo https://marselo-uz.com on this site! Find Marcelo’s biography, career, game stats and more.
Find the latest information on Khabib Nurmagomedov https://khabib-nurmagomedov.uz news and fights. Check out articles and videos detailing Khabib UFC career, interviews, wins, and biography.
Прокат и аренда автомобилей https://autorent.by в Минске 2019-2022. Сутки от 35 руб.
Coffeeroom https://coffeeroom.by – магазин кофе, чая, кофетехники, посуды, химии и аксессуаров в Минске для дома и офиса.
Latest news on the Vinicius Junior fan site https://vinisius-junior.com. Vinicius Junior has been playing since 2018 for Real Madrid (Real Madrid). He plays in the Left Winger position.
Welcome to our official website! Go deeper into Paulo Dybala’s https://paulo-dybala.com football career. Discover Dybala’s unforgettable moments, amazing talents and fascinating journey in the world of football on this site.
Seveceginiz bir kumarhane Sweet bonanza
Website dedicated to football player Paul Pogba https://pogba-uz.com. Latest news from the world of football.
The official website where you can find everything about the career of Gianluigi Buffon https://gianluigi-buffon.com. Discover the story of this legendary goalkeeper who left his mark on football history and relive his achievements and unforgettable memories with us.
починить стиральную машину починить стиральную машину .
Отличный сатй! Всем рекомендую!продать золото
Manchester City and Erling Haaland https://manchester-city.erling-haaland-fr.com explosive synergy in action. How a club and a footballer light up stadiums with their dynamic play.