- 引入依赖
<link rel="stylesheet" href="../css/viewer.css">
<script src="../js/viewer.js" type="text/javascript"></script>
<script src="../js/jquery.min.js" type="text/javascript"></script>
github下载地址:https://github.com/fengyuanch...
- 简单demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>图片预览</title>
<link rel="stylesheet" href="../css/viewer.css">
<script src="../js/viewer.js" type="text/javascript"></script>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<style>
#viewer {
display: flex;
}
#viewer li {
width: 100px;
height: 100px;
list-style: none;
}
#viewer li img {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<ul id="viewer">
<li><img data-original="https://t7.baidu.com/it/u=2708276792,219516514&fm=193&f=GIF" src="https://t7.baidu.com/it/u=2708276792,219516514&fm=193&f=GIF" alt="图片1"></li>
<li><img data-original="https://t7.baidu.com/it/u=3248413060,1409880777&fm=193&f=GIF" src="https://t7.baidu.com/it/u=3248413060,1409880777&fm=193&f=GIF" alt="图片2"></li>
<li><img data-original="https://t7.baidu.com/it/u=938052523,709452322&fm=193&f=GIF" src="https://t7.baidu.com/it/u=938052523,709452322&fm=193&f=GIF" alt="图片3"></li>
<li><img data-original="https://t7.baidu.com/it/u=91844991,1983235714&fm=193&f=GIF" src="https://t7.baidu.com/it/u=91844991,1983235714&fm=193&f=GIF" alt="图片4"></li>
<li><img data-original="https://t7.baidu.com/it/u=3796392429,3515260353&fm=193&f=GIF" src="https://t7.baidu.com/it/u=3796392429,3515260353&fm=193&f=GIF" alt="图片5"></li>
<li><img data-original="https://t7.baidu.com/it/u=2168645659,3174029352&fm=193&f=GIF" src="https://t7.baidu.com/it/u=2168645659,3174029352&fm=193&f=GIF" alt="图片6"></li>
</ul>
</body>
<script>
$(function(){
// 用法实例
var viewer = new Viewer(document.getElementById('viewer'),{
url: 'data-original'
})
});
</script>
</html>
- Viewer.js的API
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
inline | 布尔值 | false | 启用 inline 模式 |
button | 布尔值 | true | 显示右上角关闭按钮(jQuery 版本无效) |
navbar | 布尔值/整型 | true | 显示缩略图导航 |
title | 布尔值/整型 | true | 显示当前图片的标题(现实 alt 属性及图片尺寸) |
toolbar | 布尔值/整型 | true | 显示工具栏 |
tooltip | 布尔值 | true | 显示缩放百分比 |
movable | 布尔值 | true | 图片是否可移动 |
zoomable | 布尔值 | true | 图片是否可缩放 |
rotatable | 布尔值 | true | 图片是否可旋转 |
scalable | 布尔值 | true | 图片是否可翻转 |
transition | 布尔值 | true | 使用 CSS3 过度 |
fullscreen | 布尔值 | true | 播放时是否全屏 |
keyboard | 布尔值 | true | 是否支持键盘 |
interval | 整型 | 5000 | 播放间隔,单位为毫秒 |
zoomRatio | 浮点型 | 0.1 | 鼠标滚动时的缩放比例 |
minZoomRatio | 浮点型 | 0.01 | 最小缩放比例 |
maxZoomRatio | 数字 | 100 | 最大缩放比例 |
zIndex | 数字 | 2015 | 设置图片查看器 modal 模式时的 z-index |
zIndexInline | 数字 | 0 | 设置图片查看器 inline 模式时的 z-index |
url | 字符串/函数 | src | 设置大图片的 url |
build | 函数 | null | 回调函数,具体查看演示 |
built | 函数 | null | 回调函数,具体查看演示 |
show | 函数 | null | 回调函数,具体查看演示 |
shown | 函数 | null | 回调函数,具体查看演示 |
hide | 函数 | null | 回调函数,具体查看演示 |
hidden | 函数 | null | 回调函数,具体查看演示 |
view | 函数 | null | 回调函数,具体查看演示 |
viewed | 函数 | null | 回调函数,具体查看演示 |
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。