首先下載JavaScript包:
http://thecodecentral.com/wp-content/uploads/2007/08/yuilightboxwdep.zip
<html>
<head>
//根據下載的JavaScript包修改以下的路徑
<link rel="stylesheet" type="text/css" href="js/yui/assets/skins/sam/container.css" />
<script type="text/javascript" src="js/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="js/yui/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="js/yui/container/container-min.js"></script>
<script type="text/javascript" src="js/lightbox/Lightbox.js"></script>
<script type="text/javascript">...
//載入 lightbox
init = function()...{
//製作一個資料來源,含原本圖片
//用法: 圖片ID: {url: "原本圖片路徑", title:"標題" }
var dataSource = ...{
id_1:...{url:"image-big.jpg", title: '測試圖片'}
};
//建立 Lightbox 對象:
//用法:
//imageBase: Lightbox.js 的路徑
//dataSource: 資料來源
var lightbox = new YAHOO.com.thecodecentral.Lightbox(...{
imageBase:'js/lightbox',
dataSource: dataSource
});
}
//這行保持原貌
YAHOO.util.Event.on(window, 'load', init);
</script>
</head>
<body>
//加一個預覽圖片
//用法:<img src="預覽.jpg" id="圖片ID"/>
//注意:保持圖片ID和資料來源ID一致
<img src="image-small.jpg" id="id_1"/>
</body>
</html>
代碼無註解:
<html>
<head>
<link rel="stylesheet" type="text/css" href="js/yui/assets/skins/sam/container.css" />
<script type="text/javascript" src="js/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="js/yui/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="js/yui/container/container-min.js"></script>
<script type="text/javascript" src="js/lightbox/Lightbox.js"></script>
<script type="text/javascript">
init = function(){
var dataSource = {
id_1:{url:"image-big.jpg", title: '測試圖片'}
};
var lightbox = new YAHOO.com.thecodecentral.Lightbox({
imageBase:'js/lightbox',
dataSource: dataSource
});
}
YAHOO.util.Event.on(window, 'load', init);
</script>
</head>
<body>
<img src="image-small.jpg" id="id_1"/>
</body>
</html>