一行js代码搞定xue项目需要点击图片放大缩小,其实主要用的是用到了vue:class的动态切换,内容比较简单。一开始我把维护的需求想得太复杂了,和测试小姐姐聊了一下才反应过来。

两个月不到跟了四个项目,现在是维护改bug阶段,一直加班加的感觉整个人已经不是小仙女了,是黄脸婆系列~话不多说,上代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图片点击放大缩小</title> <style>
div, ul, li, span, img {
margin: ;
padding: ;
display: flex;
box-sizing: border-box;
} .vueBox{
text-align: center;
margin-left: 300px;
position: relative;
} img {
transform: scale(); /*图片原始大小1倍*/
transition: all ease .5s; } /*图片放大所用时间*/ img.active {
transform: scale(); /*图片需要放大3倍*/
position: absolute; /*是相对于前面的容器定位的,此处要放大的图片,不能使用position:relative;以及float,否则会导致z-index无效*/
z-index: ; } </style> </head>
<body> <div class="vueBox">
<img :class="{'active':isChoose}" src="http://www.baidu.com/img/bd_logo.png" style="width: 150px" @click="imgScc">
</div> <script type="text/javascript" src="js/vue.min.js"></script>
<script type="text/javascript">
const vm = new Vue({
el: ".vueBox",
data: {
isChoose:false
},
methods:{
imgScc:function () {
this.isChoose = !this.isChoose }
}
});
</script>
</body>
</html>

正常大小效果

点击后,放大2倍效果

当再次点击时,会恢复到正常大小状态

关于z-index不起作用的文章推荐:

https://blog.csdn.net/apple_01150525/article/details/76546367

最新文章

  1. SQL Server 2008 R2 企业版/开发版/标准版(中英文下载,带序列号)
  2. How to backup your blogs on cnblogs
  3. 如何在java中使用别人提供的jar包进行导入,编译,运行
  4. ruby -- 进阶学习(十四)设置background-image(解决无法获取图片路径问题)
  5. UIView和其子类的几个初始化函数执行的时机
  6. ZOJ 1610 间隔染色段树
  7. C语言中关键字auto、static、register、const、volatile、extern的作用
  8. warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  9. deepin 常用设置
  10. (6.2)vim文本编辑器
  11. 【Nginx】启动,重启,关闭命令
  12. 控件布局_FrameLayout(网格布局)
  13. Html5 标签一(文本)
  14. SpringBoot2.x使用Dev-tool热部署
  15. 弹指之间 -- Prerequisites
  16. http请求报头
  17. Tomcat数据库连接池配置
  18. Java与redis交互、Jedis连接池JedisPool
  19. “全栈2019”Java异常第十六章:Throwable详解
  20. Django 代码初体验

热门文章

  1. cocos2dx 3.2 事件机制
  2. TimeHelp 获取时间戳转换类
  3. Eclipse下使用PySpark报Could not find valid SPARK_HOME while searching
  4. servlet配置及其生命周期
  5. Python链表与反链表
  6. Python 数据处理库 pandas
  7. C#遍历XmlDocument对象所有节点名称、类型、属性(Attribute)
  8. SpringBoot入门篇--对于JSON数据的返回以及处理二
  9. mysql总结(三)
  10. python beautifulsoup爬虫