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

  1. AngkHesia表示:

    When our social anxiety leads us to consistently avoid social situations, to be very distressed when exposed to them, to have excessive fears of being negatively judged by others, or to miss out on things that we otherwise strongly want or need to do, mental health professionals may consider a diagnosis of Social Phobia also known as Social Anxiety Disorder American Psychiatric Association, 2000.
    to a significant extent.If a pharmacy offers why do doctors prescribe cipro and flagyl together and save their dollars.
    Uncontrollable laughing or crying may occur.

  2. AgnvHesia表示:

    The relation between apnea and depressive symptoms in men with severe obstructive sleep apnea: mediational effects of sleep quality.
    Many replace their trip to the pharmacy by buying valtrex safe during pregnancy for proper guidance.
    New technologies include ionization systems that react to fast-burning fires, photo-electric alarms that react quickly to smoldering fires, integrated carbon monoxide detectors and fire sprinklers, remote controls and smart-phone apps.

  3. Wqcihs表示:

    celecoxib 100mg tablet – urispas without prescription indocin 75mg canada

  4. Профессиональный сервисный центр по ремонту сотовых телефонов, смартфонов и мобильных устройств.
    Мы предлагаем: номер телефона ремонта телефонов
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  5. Wnwfonert表示:

    Sickle cell anemia Sickle cell anemia is an inherited, chronic, incurable blood disorder that causes the body to produce defective hemoglobin, the abnormal HgbS, which occurs primarily in African Americans.
    Discover great offers you can use to lisinopril cost after comparing multiple offers
    In immunosuppressed patients, there may be multiple lesions.

  6. AnedPaish表示:

    It includes 229 formulas and scoring tools, provides support for both US and SI units and offers references, detailed information and Pubmed links for each scoring tool.
    Wise people will purchase a doxycycline hyc 100mg from one of these pharmacies
    Is your father staying active?

  7. biardiova表示:

    His Majesty s meaning, turn your face Sex Tablet clomid to treat erectile dysfunction now, clomid to treat erectile dysfunction or just borrow the way Gu Min squinted and smiled Is there clomid to treat erectile dysfunction any advantage He Wuji clomid to treat erectile dysfunction nodded priligy buy

  8. Your writing has a way of making complex topics seem approachable. Thank you for demystifying this subject for me.

  9. GichardPheve表示:

    What’s up Dear, are you really visiting this website on a regular basis, if so after that you will definitely obtain good know-how.
    lee bet

  10. Simplify your projects and boost productivity with easy-to-use project management software.

  11. Ismaelfer表示:

    Hello there I am so glad I found your webpage, I really found you by error, while I was browsing on Google for something else, Nonetheless I am here now and would just like to say kudos for a marvelous post and a all round entertaining blog (I also love the theme/design), I don’t have time to read through it all at the moment but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the excellent job.
    lee bet

  12. DichaelDax表示:

    Marvelous, what a website it is! This blog presents useful information to us, keep it up.
    зеркало Dragon Money

  13. StephenDeery表示:

    This text is invaluable. How can I find out more?
    сайт казино рио бет

  14. biardiova表示:

    similar projects and should make it easier for them to find your work later buy priligy generic How to Come off Steroids 101

  15. or a mental illness sufferer.人形 エロDepending on how you cock your head,

  16. 2 Policies and guidelines about interactions between youth in positions of power,such as camp counselors,ラブドール

  17. doll}表示:

    Your Doll is actually a confirmed distributor ドール エロof sex dolls from almost 30 makers all over the world.

  18. えろ 人形表示:

    In exploring this evolving landscape, jydollit is essential to proceed with careful consideration and receptiveness, considering the ethical

  19. Scmbdh表示:

    brand benemid – buy monograph 600mg generic carbamazepine online buy

  20. RealLady Love dolls redefine companionship for those seeking emotional ドール エロlove doll relationship and Actual physical consolation, all when retaining the utmost discretion and regard for specific needs.

  21. 高級 ラブドールand pursued.Nearly all were initiated by same-age girls,

  22. or to buy some pleasurable, otherworldly, ラブドール 女性 用kinky toys you should explore for yourself or your partner.

  23. sowing doubt and confusion.By staying on the offensive,エロ ラブドール

  24. Iavzfg表示:

    where to buy gabapentin without a prescription – motrin usa buy sulfasalazine 500mg online cheap

  25. JustinBreve表示:

    сколько стоит seo оптимизация сайта https://process-seo.ru

  26. вывод. из. запоя. анонимно. ростов. вывод. из. запоя. анонимно. ростов. .

  27. вывод из запоя стационарно ростов http://vyvod-iz-zapoya-rostov112.ru .

  28. just as muscles or skills develop with usage and practice.オナドールMale and female brains may start out similar but become different over time as boys and girls are treated differently,

  29. Your writing is so eloquent and polished. It’s clear that you’re a true master of your craft.

發佈留言

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