1. 程式人生 > >JS外掛開發之LightBox圖片畫廊

JS外掛開發之LightBox圖片畫廊

工程目錄結構圖:
這裡寫圖片描述
lightBox.js封裝了寫好的外掛,直接匯入即可,這裡就不在詳細解釋程式碼了,主要介紹一下怎麼運用該外掛,下載地址:http://download.csdn.net/detail/u012612399/9373624
如果要相容IE6的話,需要匯入DD_belatedPNG.js。
html程式碼如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="css/public.css"
/>
<link rel="stylesheet" href="css/style.css" /> <script type="text/javascript" src="js/jquery-1.9.1.min.js" ></script> <script type="text/javascript" src="js/lightBox.js" ></script> <title></title> <script> $(function
(){
var lightbox = new LightBox({ speed:200, maxWidth:900, maxHeight:600 }); });
</script> </head> <body style="height: 1200px;"> class="js-lightbox" width="100" height="100"表示這個元素要啟用lightbox<br
>
data-role="lightbox" 表示這個元素要啟用lightbox<br> data-source="img/2-1.jpg"原圖的地址<br> data-group="group-2"標識當前是否屬於一個組別<br> data-id="gvfdg"圖片的唯一標識<br> data-caption="rew"當前圖片的描述文字<br> <h1>1組圖片</h1> <div> <img class="js-lightbox" width="100" height="100" data-role="lightbox" data-source="img/1-1.jpg" src="img/1-1.jpg" data-group="group-1" data-id="hfuisdhf" data-caption="hfiugyuhfa" /> <img class="js-lightbox" width="100" height="100" data-role="lightbox" data-source="img/1-2.jpg" src="img/1-2.jpg" data-group="group-1" data-id="vbdhfg" data-caption="hfiugyuhfa"/> <img class="js-lightbox" width="100" height="100" data-role="lightbox" data-source="img/1-3.jpg" src="img/1-3.jpg" data-group="group-1" data-id="jrtfgh" data-caption="hfiugyuhfa"/> </div> <h1>2組圖片</h1> <div> <img class="js-lightbox" width="100" height="100" data-role="lightbox" data-source="img/2-1.jpg" src="img/2-1.jpg" data-group="group-2" data-id="vsasde" data-caption="htfger" /> </div> <!--遮層--> <!--<div id="G-lightbox-mask"></div>--> <!--彈出層--> <!--<div id="G-lightbox-popup"> <div class="lightbox-pic-view"> <span class="lightbox-btn lightbox-prev-btn lightbox-prev-btn-show"></span> <img class="lightbox-imgage" src="img/2-2.jpg" width="100%"/> <span class="lightbox-btn lightbox-next-btn lightbox-next-btn-show"></span> </div> <div class="lightbox-pic-caption"> <div class="lightbox-caption-area"> <p class="lightbox-pic-desc">圖片標題</p> <span class="lightbox-of-index">當前索引:1 of 4</span> </div> <span class="lightbox-close-btn"></span> </div> </div>--> </body> <!--[if IE 6]> <script type="text/javascript" src="js/DD_belatedPNG.js" ></script> <script type="text/javascript"> DD_belatedPNG.fix("#G-lightbox-mask,#G-lightbox-popup .lightbox-pic-view .lightbox-btn,#G-lightbox-popup .lightbox-pic-caption"); </script> <![endif]--> </html>