-
2020-12-22 13:07:07
不啰嗦直接上代码
1.安装vue插件 v-viewer
npm install v-viewer
2.在vue的mian.js里面引入Viewer
import 'viewerjs/dist/viewer.css' import Viewer from 'v-viewer' Vue.use(Viewer) // 这里是插件的默认设置 Viewer.setDefaults({ zIndexInline: 9999 })
3.HTML页面
<template> <div class="el-input el-input--small" v-if="demoList.length>0" > <viewer> <img width="150" v-for="src in demoList" :src="src.imgurl" :key="src.name" > </viewer> </div> </template> <script> export default { data() { return { demoList: [ { name: 'a', imgurl: require('../../assets/timg1.jpg') } ] } } } </script>
4.页面效果
5.可以自定义属性
Vue.use(Viewer, { defaultOptions: { zIndex: 9999, inline: false, button: true, navbar: false, title: false, toolbar: true, tooltip: false, movable: true, zoomable: true, rotatable: true, scalable: false, transition: true, fullscreen: false, keyboard: false } })
viewer其他属性
参数配置
如果要改变全局的默认样式,可以使用 Viewer.setDefaults(options)
参数名称 参数类型 默认值 说明 initialViewIndex Number 0 定义用于查看的图像的初始索引 inline Boolean false 支持 inline mode button Boolean true 是否显示查看图片时右上角的关闭按钮 navbar Boolean / Number true 是否显示底部导航栏 0
或者false
:不显示1
或者true
:显示2
:当屏幕宽度大于768px时显示3
:当屏幕宽度大于992px时显示4
:当屏幕宽度大于1200px时显示title Boolean / Number /
Function / Arraytrue 0
或者false
时不显示1
或者true
或者function
或者array
时显示2
:当屏幕宽度大于768px时显示3
:当屏幕宽度大于992px时显示4
:当屏幕宽度大于1200px时显示function
在函数体内返回标题array
第一个参数表示可见性(0-4) 第二个参数就是标题toolbar Boolean / Number / Object true 标题栏是否显示和布局 0
或者false
时不显示1
或者true
或者时显示2
:当屏幕宽度大于768px时显示3
:当屏幕宽度大于992px时显示4
:当屏幕宽度大于1200px时显示tooltip Boolean true 放大或缩小时显示的百分比的文字提示 true
: 显示false
: 不显示movable Boolean true 是否可以拖动图片 zoomable Boolean true 是否可以缩放图片 rotatable Boolean true 是否可以旋转图片 scalable Boolean true 是否可以缩放图片 transition Boolean true 为一些特殊元素启用CSS3转换。 fullscreen Boolean true 允许全屏播放 keyboard Boolean true 启用键盘支持 backdrop Boolean / String true 启用 modal 为false的时候不支持点击背景关闭 loading Boolean true 加载图片的时候的loading图标 loop Boolean true 是否可以循环查看图片 interval Number 5000 定义图片查看器的最小的宽度 minWidth Number 200 定义图片查看器的最小的高度 minHeight Number 100 播放图片时 距离下一张图片的间隔时间 zoomRatio Number 0.1 利用鼠标滚轮缩放图片时的比例 minZoomRatio Number 0.01 缩小图片的最小比例 maxZoomRatio Number 100 放大图片的放大比例 zIndex Number 2015 定义查看器的CSS z-index值 modal 模式下 zIndexInline Number 0 定义查看器的CSS z-index值 inline 模式下 url String / Function src 原始图像URL
如果是一个字符串,应该图像元素的属性之一
如果是一个函数,应该返回一个有效的图像URLcontainer Element / String body 将查看器置于modal模式的容器
只有在 inline为 false的时候才可以使用filter Function null 过滤图像以便查看(如果图像是可见的,应该返回true) toggleOnDblclick Boolean true 当你放大或者缩小图片时 双击还原 ready Function null 当查看图片时被触发的函数 只会触发一次 show Function null 当查看图片时被触发的函数 每次查看都会触发 shown Function null 当查看图片时被触发的函数 每次查看都会触发 在show之后 hide Function null 当关闭图片查看器时被触发的函数 每次关闭都会触发 hidden Function null 当关闭图片查看器时被触发的函数 每次关闭都会触发 在hide之后 view Function null 当查看图片时被触发的函数 每次查看都会触发 在shown之后 viewed Function null 当查看图片时被触发的函数 每次查看都会触发 在view之后 zoom Function null 在图片缩放时触发 zoomed Function null 在图片缩放时触发 在 zoom之后 toolbar Object详解
key值列表: "zoomIn", "zoomOut", "oneToOne", "reset", "prev", "play", "next", "rotateLeft", "rotateRight", "flipHorizontal", "flipVertical"
key值名称 说明 zoomIn 放大图片的按钮 zoomOut 缩小图片的按钮 reset 重置图片大小的按钮 prev 查看上一张图片的按钮 next 查看上一张图片的按钮 play 播放图片的按钮 rotateLeft 向左旋转图片的按钮 rotateRight 向右旋转图片的按钮 flipHorizontal 图片左右翻转的按钮 flipVertical 图片上下翻转的按钮 {key:number|Boolean} 显示或者隐藏对应key的按钮 为Number的时候为可见性
{key: String } 自定义按钮的大小
{ key: Function } 自定义按钮点击的处理
{ key: { show: Boolean | Number, size: String, click: Function } 自定义按钮的每个属性更多相关内容 -
vue鼠标悬停图片放大特效
2021-04-25 05:37:38vue鼠标悬停图片放大特效是一款基于vue.js跟css3制作的相册图片悬停弹出3d放大展示代码。 -
图片在表格中,鼠标经过图片上方,图片有放大预览效果 (vue+element )
2020-03-07 17:31:39element的鼠标移到图片时,放大预览效果。实现思路:element的 el-table + el-popover <template> <div class="test-image"> <el-table :data="tabData" border> <el-table-column align=....element
的鼠标移到图片时,放大预览效果。实现思路:element
的el-table
+el-popover
<template> <div class="test-image"> <el-table :data="tabData" border> <el-table-column align="center" label="示例图片" width="80" :show-overflow-tooltip="true" prop="image_url"> <template slot-scope="scope"> <el-popover placement="right" :title="scope.row.imgName" trigger="hover" width="250" > <el-image slot="reference" :src="scope.row.image_url" :alt="scope.row.image_url"></el-image> <el-image :src="scope.row.image_url"></el-image> </el-popover> </template> </el-table-column> <el-table-column align="center" label="标题" width="160" :show-overflow-tooltip="true" prop="imgName"></el-table-column> </el-table> </div> </template> <script> export default { data () { return { tabData: [ { image_url: 'https://img.yzcdn.cn/public_files/2017/10/24/e5a5a02309a41f9f5def56684808d9ae.jpeg', imgName: 'apple' }, { image_url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', imgName: 'bird' }, { image_url: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg', imgName: 'deer' } ] } } } </script>
注:
①el-table
绑定的data
属性是表格渲染的列表tabData
,el-table-column
是表格的单元格,它的prop
的值是tabData
中的键名;show-overflow-tooltip
是内容过多显示tooltip
;
②el-popover
是element
的Popover
弹出框,placement
是出现的位置
③popover
中有slot="reference"
的元素是当前触发popover
的元素。
④popover
中trigger="hover"
,表示hover
时触发所以上面的:
<el-popover placement="right" :title="scope.row.imgName" trigger="hover" width="250" > <el-image slot="reference" :src="scope.row.image_url" :alt="scope.row.image_url"></el-image> 是触发了popover的元素,即鼠标移动到这张图片上,下面那张图片就会显示,且宽为popover中的定义的 width="250"; <el-image :src="scope.row.image_url"></el-image> 它只是popover的显示内容,popover 弹出框被触发,它就显示 </el-popover>
效果如图( 鼠标经过第三张图 ):
-
小结:
① Table中的,表格自定义列模板
通过Scoped slot
可以获取到row
,column
,$index
和store
(table
内部的状态管理)的数据;
参考:https://element.eleme.cn/#/zh-CN/component/table#table-column-scoped-slot② Popover 弹出框
trigger
属性用于设置何时触发Popover
,支持四种触发方式:hover
,click
,focus
和manual
。对于触发Popover
的元素,有两种写法:使用slot="reference"
的具名插槽,或使用自定义指令v-popover
指向Popover
的索引ref
。
-
vue实现点击图片放大效果
2020-08-29 16:51:26主要为大家详细介绍了vue实现点击图片放大效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 -
Vue实现(图片预览、鼠标V滚动、点击放大、图片轮播等功能)
2021-11-05 22:15:47Vue 图片预览(鼠标V滚动、点击放大、缩小图片) 使用插件v-viewer 1.安装v-viewer npm install v-viewer -s 2.在main.js引入js,css import Viewer from 'v-viewer' import 'viewerjs/dist/viewer.css' Vue.use...1.安装v-viewer
npm install v-viewer -s
2.在main.js引入js,css
import Viewer from 'v-viewer' import 'viewerjs/dist/viewer.css' Vue.use(Viewer, { defaultOptions: { zIndex: 9999 } }) Viewer.setDefaults({ Options: { "inline": true, // 是否启动inline模式 "button": true, // 是否显示右上角关闭按钮 "navbar":true, // 是否显示缩略图导航 "title": true, // 是否显示当前图片的标题 "toolbar": true, // 是否显示工具栏 "tooltip": true, // 是否显示缩放百分比 "movable": true, // 图片是否可移动 "zoomable": true, // 图片是否可缩放 "rotatable": true, // 图片是否可旋转 "scalable": true, // 图片是翻转 "transition": true, // 是否使用css3过渡 "fullscreen": true, // 播放时是否全屏 "keyboard": true, // 是否支持键盘 "url": "data-source" // 设置大图片的url } });
3.页面使用
<el-row :gutter="3"> <el-col :spn="10" v-for="(item,index) in urls" :key="index" style="width: 300px;" class="row_class"> <viewer :images="item" class="viewer" ref="viewer" :zoomable="false"> <img :src="item" :key="index" style="width: 300px"> </viewer> <div> <el-tooltip class="classDelete" effect="dark" content="删除" placement="top"> <span class="Delete" @click="deleteImg(item,index)" ><i class="el-icon-delete"></i></span> </el-tooltip> </div> </el-col> </el-row>
4.效果图
-
vue图片预览插件,支持鼠标缩放:useful-photo-preview
2021-06-11 18:40:00我现在在做的vue项目使用的组件库是Ant Design的vue版本,里面有个图片组件,但是用起来不顺心。在bing找了一些,要么不适配vue3.x,要么就是直接报错????。 于是就自己整了一个,希望也可以帮助像我一样的小伙伴???...前言
我现在在做的vue项目使用的组件库是Ant Design的vue版本,里面有个图片组件,但是用起来不顺心。在bing找了一些,要么不适配vue3.x,要么就是直接报错😥。
于是就自己整了一个,希望也可以帮助像我一样的小伙伴🤗
我第一次发布npm包,也是第一次写文章,欢迎大佬们评论
介绍
此插件使用简单方便,只有一个api,一个事件,避免了复杂的文档和使用教程。
其依赖于screenfull,安装插件时会自动安装,如出现未找到screenfull,使用
npm i screenfull
安装即可源码在github,一起学习,共同进步。希望有个star🙄
如何使用
已发布于npm,可直接安装使用
安装
npm i useful-photo-preview
使用
- 引用
import imgShow from useful-photo-preview
- 使用
<img-show :src="img_url" @close="onclose"></img-show>
功能
-
全屏预览,复位,左右旋转
-
鼠标滚轮放大缩小
-
鼠标拖动移动位置
-
双击进入和退出全屏预览
-
点击空白位置退出(调用@close事件)
-
ESC键退出(调用@close事件)
-
宽缩放最小150px 左右,最大5000px 左右
预览
全屏时背景会变成纯黑色
API
-
参数
- :src 图片链接,或base64数据
-
事件
- @close 关闭事件
- 引用
-
vue 移动端图片预览的方法使用总结
2020-05-28 09:55:29方法一: import VueImageSwipe from 'vue-image-...import 'vue-image-swipe/dist/vue-image-swipe.css' Vue.use (VueImageSwipe); <div v-for="(item,index) in environmentalList" :key="index+'item'" ... -
vue3 elementui table popover上的图片鼠标移上去图片预览
2021-08-18 14:16:02height: 80%" > </el-popover> </template> </el-table-column> 之前用vue2写,结果slot和slot-scope不行了,在vue2.6及已上版本,slot 和slot-scope已经开始废弃, 有了新的替代: v-slot,v-slot只能用在template ... -
Vue PC端图片预览插件
2020-12-20 13:50:06记录一下项目中遇到的问题,留做笔记:需求:在项目中,需要展示用户上传的一些图片,我从后台接口拿到图片url后放在页面上展示,因为被图片我设置了宽度限制(150px),所以图片被缩放了,需求说加一个图片预览的功能... -
vue实现点击图片预览,上方显示该预览大图,同时为下方图片预览列表,实现透明遮罩。
2022-04-30 22:23:27同时实现下面图片预览的白色透明遮罩。当哪个被点击,则白色遮罩消失,其他依然存在显示。 3.首先我们定义一下ui结构: <!-- 图片预览区 --> <div class="exhibitionimg"> <!-- element选择... -
基于vue的鼠标移动放大部分区域图片(仿京东商品图片放大效果)
2022-03-18 12:27:47基于vue的鼠标移动放大部分区域图片(仿京东商品图片放大效果) -
vue 图片预览(鼠标滚动、点击放大、缩小图片)
2020-12-19 11:55:36一、插件v-viewer1、安装插件npm install v-viewer -s2、main.js引入js、cssimport Viewer from 'v-viewer'import 'viewerjs/dist/viewer.css'Vue.use(Viewer, {defaultOptions: {zIndex: 9999}})Viewer.setDefaults... -
vue3 ant design vue图片上传预览
2021-08-05 13:28:39// } // } //预览pdf文件 // const viewfile = async () => { // let pdfUrl = await beforeUpload(state.fileListPdf) // if (pdfUrl) { // previewImage.value = pdfUrl // previewVisible.value = true // } // }... -
基于Vue的图片预览插件
2020-04-08 18:36:55Vue图片预览插件,支持左右滑动切换,适配移动端和PC端,支持移动端手势缩放,上划关闭。支持缩放归位效果,过渡自然 -
vue viewerjs预览图片
2022-02-15 09:40:54vue 实现图片预览 viewerJs -
用vue实现,鼠标悬停放大图片,根据鼠标位置倾斜图片网页源码
2022-04-17 13:31:54大家好,今天给大家介绍一款,用vue实现的,鼠标悬停放大图片,并根据鼠标位置倾斜图片前端网页源码(图1)。送给大家哦,获取方式在本文末尾。 图1 鼠标悬停放大图片,鼠标移动图片就会进行相应角度的倾斜,有... -
【vue手写图片预览组件】在vue2.0项目中手写图片预览组件,旋转、放大、滚动、下载等功能
2022-04-26 18:24:05【vue手写图片预览组件】在vue2.0项目中手写图片预览组件,旋转、放大、滚动、下载等功能,同时做了载入动画处理。 -
vue 图片,视频点击预览按钮方法
2021-11-12 14:58:52图片 使用el-image-viewer组件 写之前注意引入安装组件!!! 主要代码: <div class=""> <el-image-viewer v-if="showViewer" :on-close="()=>{showViewer=false}" :url-list="[pic]"/> </div&... -
vue+ElementUI实现点击图片预览大图和预览视频
2022-03-05 13:58:37Vue+ElementUI实现在表格中点击图片预览大图和预览视频 -
vue中实现图片预览放大,缩小,旋转等功能, 使用viewerjs
2020-11-10 17:55:02之前使用过v-viewer实现图片查看的功能,但是不知道今年怎么回事,node线上的包下载下来不能用了,实现不了效果,又找到了一另一个好用的插件,那就是viewjs。 实现效果: 实现步骤: 1、安装插件 npm ... -
vue element-ui实现图片鼠标控制图片移动
2020-04-27 23:06:231 -
Vue 实现图片监听鼠标滑轮滚动实现图片缩小放大功能
2021-06-09 14:23:10Vue 实现图片监听鼠标滑轮滚动实现图片缩小放大功能 其实想要实现功能很简单,就是在一张图片上监听鼠标滑轮滚动的事件,然后根据上滚还是下滚实现图片的缩放。 其实就是这种效果: 其实代码不是很难。 HTML代码: ... -
看我如何使用Vue实现图片的上传以及大图预览功能
2021-07-02 20:54:29下面的代码,笔者基于Vue.js,使用了element-ui组件类库实现的,功能包括:支持图片的上传、图片类型以及图片大小校验、图片列表展示、图片大图预览功能、图片空白处点击关闭大图功能。 废话不多说了,直接上代码: ... -
vue 鼠标移入移出(hover)切换显示图片
2021-08-06 14:48:09使用一个变量来表示鼠标移入或移出的状态,鼠标移入事件mouseenter,移出事件mouseleave,在这两个事件中来修改这个变量。 注意:移出事件别用mouseout。 代码: 断开连接 data: exit: require("@/assets/img/exit... -
Vue点击图片预览(可旋转、缩放、上下切换)
2020-11-25 10:53:42vue插件v-viewer的使用目的新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants... -
用vue实现点击图片预览浏览器满屏大图
2020-08-04 10:05:49npm install vue-directive-image-previewer -D 引入插件 import VueDirectiveImagePreviewer from 'vue-directive-image-previewer' import 'vue-directive-image-previewer/dist/assets/style.css' Vue.use...