vue.js 实现点击展开收起动画效果
作者:是渔不是鱼 发布时间:2024-05-29 22:47:44
标签:vue.js,点击,展开,收起
最近公司项目加了个页面,其中要求是这样的,点击对应列表,展开和收起,其实就是显示和隐藏内容部分;说来惭愧,我花了半天时间才搞出来(自黑一下~),接下来分享给大家,先上效果图:
vue页面:
<template>
<div class="dealRecord-wrap">
<div class="title-contant" v-for="(item,index) in items " >
<div class="title" @click="showHide(index)">
<h3>2018年0{{index+6}}月</h3>
<div class="number">800笔<i></i></div>
</div>
<div class="contant">
<ul>
<li v-for="i in item.allNumber">
{{index+6}}
</li>
</ul>
</div>
</div>
</div>
</template>
<script>
export default{
data(){
return{
items:[
{v:'qqq',allNumber:1},
{v:'aaa',allNumber:2},
{v:'qqq',allNumber:3},
],
}
},
created(){
document.body.style.backgroundColor = '#f6f6f6';
},
mounted(){
for(var i=0;i<3;i++){ //这里取值自后台返回的长度,设置页面渲染完成后是否展开,此处不展开
document.getElementsByClassName('contant')[i].style.height = '0px';
}
},
components:{
},
methods:{
showHide(index){ //点击展开收起
let contant = document.getElementsByClassName('contant')[index]; //这里我们通过参数index来让浏览器判断你点击的是哪一个列表
let height = contant.getBoundingClientRect().height; //获取页面元素的当前高度
document.getElementsByTagName('i')[index].style.transform = !!height?'rotateX(0deg)':'rotateX(180deg)';
if (!!height) {
contant.style.height = height + 'px';
let f = document.body.offsetHeight; //强制相应dom重绘,使最新的样式得到应用
contant.style.height = '0px';
} else {
contant.style.height = 'auto';
height = contant.getBoundingClientRect().height;
contant.style.height = '0';
let f = document.body.offsetHeight;
contant.style.height = height + 'px';
}
}
},
beforeDestroy(){
document.body.style.backgroundColor = '#fff';
}
}
</script>
<style type="text/scss" lang="scss" scoped>
.dealRecord-wrap{margin-bottom: 100px;
.title-contant{overflow: hidden; /* 这个是重点 */
.title{height: 84px;padding: 0 24px;border-bottom: 1px solid #eaeaea;/*px*/
h3{height: 84px;font-size: 28px;color: #333;display: flex;align-items: center;float: left;;margin-left: 10px;}
.number{height: 84px;font-size: 24px;color: #666;display: flex;align-items: center;float: right;}
.number i{display: inline-block;width: 23px;height: 13px;background: url('../../assets/images/icon_dropup@2x.png');background-repeat: no-repeat;background-size: 23px 13px;background-position: right 6px center;padding-right: 35px;display: flex;align-items: center; float: right;transform:rotateX(0deg);}
}
.contant{background: #fff;transition: height 1s; /* 这个也是重点 */
ul li{padding: 0 24px;height: 142px;display: flex;align-items: center;}
ul li:not(:last-child){border-bottom: 1px solid #f6f6f6;/*px*/}
}
}
}
</style>
来源:http://www.cnblogs.com/silent007/p/9188486.html


猜你喜欢
- python2.7,下面是跑在window上的,稍作修改就可以跑在linux上。实测win7和raspbian均可,且raspbian可以直
- 1、按照javaweb项目的要求逐步建立搭建起机构,具体的类包有:model 、db、dao、test;具体的架构详见下图:2、根据搭建的项
- 前言Vue会对我们在data中传入的数据进行拦截:对象:递归的为对象的每个属性都设置get/set方法数组:修改数组的原型方法,对于会修改原
- 为什么使用Python 假设我们有这么一项任务:简单测试局域网中的电脑是否连通.这些电脑的ip范围从19
- 关于Variable和Tensor旧版本的Pytorch中,Variable是对Tensor的一个封装;在Pytorch大于v0.4的版本后
- 1.什么是SQL注入 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL
- 从MySQL 5.0.2开始,通过mysql_stmt_attr_set() C API函数实现了服务器端光标。服务器端光标允许在服务器端生
- 本来想把这个页面用jade渲染出来、评论部分用vue,但是想了想觉得麻烦,最后还是整个用vue的组件搞定他吧。 先上在线demo:http:
- 简单的LSTM问题,能够预测一句话的下一个字词是什么固定长度的句子,一个句子有3个词。使用one-hot编码各种引用import keras
- Selenium 是一个可以让浏览器自动化地执行一系列任务的工具,常用于自动化测试。不过,也可以用来给网页截图。目前,它支持 Java、C#
- 今天看到了mlxtend的包,看了下example集成得非常简洁。还有一个吸引我的地方是自带了一些data直接可以用,省去了自己造数据或者找
- 实现效果如下: 需求:由于后台搜索选项有很多,影响页面美观,所以一进来要隐藏一部分搜索项,只保留1行,点击【展开搜索】按钮的时候才
- 1. 传值与传址的区别传值就是传入一个参数的值,传址就是传入一个参数的地址,也就是内存的地址(相当于指针)。他们的区别是如果函数里面对传入的
- MySQL 提供了几种用于查看服务器版本的方法,本文给大家做个简单的介绍。方法一:登录 MySQL每次通过 mysql 客户端连接服务器之后
- 前言当我们运行测试函数时,我们希望确保测试函数在运行结束后,可以自己清理掉对环境的影响。这样的话,它们就不会干扰任何其他的测试函数,更不会日
- kafka的认证方式一般有如下3种:1.SASL/GSSAPI 从版本0.9.0.0开始支持2.SASL/PLAIN 从版本0.10.0.0
- 安装MySQL ODBC驱动官方说法:MySQL ODBC 驱动程序负责在开放式数据库连接 API (ODBC API) 的帮助下访问 My
- 一.思路1.整体思路2.代码思路思路很简单,就是用python发送请求,提取响应体中的状态码加以判断,最后保存到本地txt文本中,以实现网站
- 1.相关基础知识介绍 在Vim中,有四个与编码有关的选项
- python redis连接 有序集合去重的代码如下所述:# -*- coding: utf-8 -*- import redisfrom