标题: 给你的网站添加预览图片功能
时间: 2020-03-19发布,2020-03-19修改
经过@泰戈尔会游泳 的启发,我也整理了一些IDEA插件见此,在里面插图时由于文章页宽度有限,图片上具体文字看不清,如:
这种情况看不到细节用户体验很差,于是我上网找是否有预览图片的js,一搜乖乖全是代码,放本地跑还没效果,大概是我方法有误。于是再有继续找呀找呀,直到找到这款插件
调用方法很简单,引入其js、css,在用js调用下即可,如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/viewer.min.css">
<script src="js/viewer.min.js"></script>
</head>
<body>
<img src="./img/tibet-1.jpg" alt="图片1">
<img src="./img/tibet-2.jpg" alt="图片2">
</body>
<script>
new Viewer(document.body, {
url: 'data-original',
button: true,
navbar: true
});
</script>
</html>
new Viewer()第二个参数为配置项,可以不写默认即可
new Viewer(document.body);
new Viewer()第一个参数即图片所在容器,例如在hu60图片只在文章页topic-content的div里
new Viewer(document.getElementsByClassName("topic-content")[0]);
演示地址:https://cway.top/post/653.html
下载地址:https://www.lanzous.com/iaf3acf
第二个参数配置表:
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
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 | 回调函数,具体查看演示 |
『回复列表(4|隐藏机器人聊天)』