vue实现点击图片放大效果
作者:```...简单点 时间:2024-05-21 10:30:28
本文实例为大家分享了vue点击图片放大展示的具体代码,供大家参考,具体内容如下
1.建立子组件,来实现图片方 * 能: BigImg.vue
<template>
<!-- 过渡动画 -->
<transition name="fade">
<div class="img-view" @click="bigImg">
<!-- 遮罩层 -->
<div class="img-layer"></div>
<div class="img">
<img :src="imgSrc">
</div>
</div>
</transition>
</template>
<script>
export default {
props: ['imgSrc'],//接受图片地址
methods: {
bigImg() {
// 发送事件
this.$emit('clickit')
}
}
}
</script>
<style scoped>
/*动画*/
.fade-enter-active,
.fade-leave-active {
transition: all .2s linear;
transform: translate3D(0, 0, 0);
}
.fade-enter,
.fade-leave-active {
transform: translate3D(100%, 0, 0);
}
/* bigimg */
.img-view {
position: inherit;
width: 100%;
height: 100%;
}
/*遮罩层样式*/
.img-view .img-layer {
position: fixed;
z-index: 999;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.7);
width: 100%;
height: 100%;
overflow: hidden;
}
/*不限制图片大小,实现居中*/
.img-view .img img {
max-width: 100%;
display: block;
position: absolute;
left: 0;
right: 0;
margin: auto;
z-index: 1000;
}
</style>
2.在父类中使用子组件:
<template xmlns:v-on="http://www.w3.org/1999/xhtml">
<div class="contents">
<div class="group">
<div class="special">
<span v-text="pagedata.subtitle"></span>
</div>
<span class="text-muted" v-text="pagedata.headline"></span>
<div class="group_img">
<!-- 放大图片 -->
<big-img v-if="showImg" @clickit="viewImg" :imgSrc="imgSrc"></big-img>
<div class="text" v-text="pagedata.article"></div>
<img id="smallImg" :src="pagedata.imgurl" @click="clickImg($event)">
</div>
</div>
</div>
</template>
<script>
import BigImg from '../../index/moduleStyles/BigImg.vue';
export default {
data () {
return {
showImg:false,
imgSrc: ''
}
},
props: ['pagedata'],
computed: {},
components: { 'big-img':BigImg},
methods: {
clickImg(e) {
this.showImg = true;
// 获取当前图片地址
this.imgSrc = e.currentTarget.src;
},
viewImg(){
this.showImg = false;
},
},
watch: {},
}
</script>
<style>
</style>
来源:http://www.cnblogs.com/yysbolg/p/7365697.html
标签:vue,点击放大
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解mysql 获取某个时间段每一天、每一个小时的统计数据
2024-01-17 13:01:47
![](https://img.aspxhome.com/file/2023/4/113974_0s.jpg)
SQL Server 对表的主键设计问题及解决办法
2010-06-07 13:29:00
asp+ajax版四级联动菜单(数据库)
2009-07-03 15:40:00
python创建关联数组(字典)的方法
2021-11-22 06:51:18
Python只用40行代码编写的计算器实例
2023-07-30 07:16:40
![](https://img.aspxhome.com/file/2023/4/61224_0s.jpg)
C# 操作 access 数据库的实例代码
2024-01-28 15:05:11
Python实现抓取腾讯视频所有电影的示例代码
2021-09-11 13:17:37
![](https://img.aspxhome.com/file/2023/7/77657_0s.jpg)
python中map的基本用法示例
2023-09-24 15:56:26
![](https://img.aspxhome.com/file/2023/1/124141_0s.png)
SQL一条语句统计记录总数及各状态数
2024-01-17 21:53:35
专家教你安装 MySQL的与MySQL GUI Tools
2012-01-29 17:59:05
用python生成一张壁纸实例代码
2022-06-06 10:26:51
![](https://img.aspxhome.com/file/2023/7/127707_0s.png)
PHP模板引擎Smarty中变量的使用方法示例
2023-11-14 23:32:25
python 爬虫基本使用——统计杭电oj题目正确率并排序
2021-11-25 17:16:35
Python实现简单的四则运算计算器
2022-12-29 20:44:08
使用pandas库对csv文件进行筛选保存
2022-12-25 04:55:10
![](https://img.aspxhome.com/file/2023/7/112917_0s.png)
[译]2009年海外Web设计风潮(下)
2009-01-23 09:34:00
![](https://img.aspxhome.com/file/UploadPic/20091/23/trend-38-39s.gif)
pip install urllib2不能安装的解决方法
2022-05-27 12:25:13
python学习教程之Numpy和Pandas的使用
2022-12-14 12:41:06
![](https://img.aspxhome.com/file/2023/1/120281_0s.jpg)
SEM之医疗网站跳出率 逼迫访客跳出网站的六宗罪
2012-03-05 20:13:36
mysql 8.0.12 安装配置方法并修改密码
2024-01-19 14:49:05
![](https://img.aspxhome.com/file/2023/3/119703_0s.jpg)