首先下载JavaScript包:
<html>
<head>
//根据下载的JavaScript包修改以下的路径
<link type="text/css" href="https://www.jb51.net/js/yui/assets/skins/sam/container.css" />
<script type="text/javascript" src="https://www.jb51.net/js/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="https://www.jb51.net/js/yui/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/js/yui/container/container-min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/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="https://www.jb51.net/预览.jpg"/>
//注意:保持图片ID和数据源ID一致
<img src="https://www.jb51.net/image-small.jpg"/>
</body>
</html>
代码无注解:
<html>
<head>
<link type="text/css" href="https://www.jb51.net/js/yui/assets/skins/sam/container.css" />
<script type="text/javascript" src="https://www.jb51.net/js/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="https://www.jb51.net/js/yui/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/js/yui/container/container-min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/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="https://www.jb51.net/image-small.jpg"/>
</body>
</html>
JavaScript 仿关机效果的图片层
内容版权声明:除非注明,否则皆为本站原创文章。