vue伸缩效果_vuejs实现折叠面板展开收缩动画效果
vuejs通过css3实现元素固定高度到auto高度的动画和auto高度到固定高度的动画。
循环列表,html:
-
{{item.content}}
【展开】【收缩】
在css上加上动画transition
.newslist ul li p {
font-size: 14px;
color: #555;
line-height: 25px;
height: 50px;
overflow: hidden;
transition: height .3s;
}
重点是下面js的实现:
分为两种情况:
(一)初始状态是收缩时:
import Vue from 'vue'
export default {
props: ['newslist'],
data() {
return {
liConHeight: 50 // 两行文字的高度
}
},
methods: {
open(item, i) {
const liCon = this.$refs.liCon[i]
var height = liCon.offsetHeight
if (height === this.liConHeight) { // 展开
liCon.style.height = 'auto'
height = liCon.offsetHeight
liCon.style.height = this.liConHeight + 'px'
var f = document.body.offsetHeight // 必加
liCon.style.height = height + 'px'
} else { // 收缩
liCon.style.height = this.liConHeight + 'px'
}
if (!item.openFlag) {
Vue.set(item, 'openFlag', true)
} else {
Vue.set(item, 'openFlag', false)
}
}
}
}
(二)初始状态是展开时:
稍微改动:
var height = liCon.offsetHeight // 也可以是liCon.getBoundingClientRect().height
if (height === this.liConHeight) { // 展开
liCon.style.height = 'auto'
height = liCon.offsetHeight
liCon.style.height = this.liConHeight + 'px'
liCon.style.height = height + 'px'
} else { // 收缩
liCon.style.height = height + 'px'
var f = document.body.offsetHeight
liCon.style.height = this.liConHeight + 'px'
}
总结
以上所述是小编给大家介绍的vuejs实现折叠面板展开收缩动画效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)