vue实现点击图片放大效果
作者:```...简单点 发布时间:2024-05-21 10:30:28
标签:vue,点击放大
本文实例为大家分享了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


猜你喜欢
- 1.INPUT和图片按钮对齐:<form method="post" action="
- 主要用到requests和bf4两个库将获得的信息保存在d://hotsearch.txt下import requests;import b
- 用opencv处理一下pillow也可以,但是试过有时候会把图片自动旋转180°,cv没有这个问题import osfrom
- 一、行转列— case+group bymysql> CREATE TABLE `TEST_TB_GRADE` (
- 这篇文章主要介绍下如何创建并调用函数。print():是打印放入对象的函数 len():是返回对象长度的函数 input():是让用户输入对
- 在mysql网站时拿到的rpm包只能用root安装,不支持relocate用源码安装后./configure --prefix=/home/
- 前言这篇文章给大家讲解的是在vue-cli脚手架中如何配置vue-router前端路由的相关内容,分享出来供打击参考学习,下面来一起看看详细
- 在Microsoft SQL Server 2000中,用于数据存储的实用工具是数据库。数据库的物理表现是操作系统文件,即在物理上,一个数据
- 似乎讨论分页的人很少,难道大家都沉迷于limit m,n?在有索引的情况下,limit m,n速度足够,可是在复杂条件搜索时,where s
- 一,开窗函数的语法开窗函数的语法为:over(partition by 列名1 order by 列名2 ),括号中的两个关键词partit
- 作者:Tr4c3 '为了保持脚本的通用性,放弃了 and (select col_name(objec
- Python的绘图库也允许用户创建优雅的图形,本章给大家介绍的是关于ggplot绘制画图的技巧,ggplot2建立在grid系统上,这个系统
- 1线性回归1.1简单线性回归在简单线性回归中,通过调整a和b的参数值,来拟合从x到y的线性关系。下图为进行拟合所需要优化的目标,也即是MES
- 1. 一些常用的 MySQL 命令#连接MySQLmysql -h 127.0.0.1 -u UserName -p pwd -
- 具有不同标记颜色和大小的散点图演示。演示结果:实现代码:import numpy as npimport matplotlib.
- 本文实例为大家分享了python可视化动态CPU性能监控的具体代码,供大家参考,具体内容如下打算开发web性能监控,以后会去学js,现在用m
- 首先我们解压$ unzip p8202632_10205_LINUX.zip解压后我们会发现多出了个文件夹,他是:Disk1,进入Disk1
- 如下所示:function makeAcquire($nUsers,$nAwards) { &
- 可能大家在日常工作中会遇到这么个问题,现在基本的linux系统都是自带老版本的python2.7.x版本,我又不想用老版本,但直接升级可能会
- 一,问题背景作者在用tensorflow做实验时,import tensorflow忽然报错:cannot import name '