div点击展开 vue_vue实现展开全部,收起全部

1.给数组的每一项添加是否展开或收起的标志:‘toggleShowDes’和长度限制的标志:‘ifMore’

/*获取评论列表*/

getComment: function(flag){

var m = this;

if (!flag) {

m.conmontShow = false;

}

$.get('/subject/getComment',{id:m.topicItem.questionId,page:1},function(ret){

if (ret.errCode==0){

m.conmontShow = true;

var arr = ret.data.lists;

arr.forEach(function (v, i) {

if ($.inArray(zhentiListVm.userId, v.pointOfPraiseRecord) < 0) {

v.fabulous = false;

} else {

v.fabulous = true;

};

v.toggleShowDes = false;

v.ifMore=false;

});

setTimeout(function () {

$('.intro').each(function (i, v) {

if (arr[i].content.length > 44) {

console.log(123)

arr[i].ifMore=true

} else {

arr[i].ifMore=false;

console.log(456)

}

})

});

zhentiListVm.commentLists = arr;

zhentiListVm.userInfo = ret.data.users;

}else{

console.log(ret)

}

},'json')

},

2.根据内容判断状态

[[ item.content ]]

收起全部

[[ item.content ]]

展开全部

3.点击展开和收起的函数

/*简介展开*/

spread: function (item,index,targetState) {

console.log(index)

var self = this;

if(targetState) {

self.commentLists.forEach(function (v, i) {

console.log(i);

v.toggleShowDes=(i== index);

});

}else{

item.toggleShowDes=false;

}

}

4.css样式

.des1, .des2 {

position: relative;

}

.des1 {

word-break: break-all;

height: .66rem;

display: -webkit-box;

-webkit-box-orient: vertical;

-webkit-line-clamp: 2;

overflow: hidden;

}

.height4{height: .4rem}

.absolut{position: absolute}

/*.mores {

background-image: linear-gradient(-180deg, rgba(255, 255, 255, 0) 0%, #ffffff 100%);

height: .66rem;

left: 0;

bottom: 0;

}*/

.more-operation-collect{

position: absolute;

height: 0.66rem;

color: #1facfc;

right: 12px;

}

.more-operation {

position: absolute;

height: 0.66rem;

color: #1facfc;

right: 12px;

/*padding-right: 127px;*/

}

.collect{ bottom: 2px;}

.open{ bottom: -12px;}

.more-operation span {

margin-right: 6px;

}

.retract {

-webkit-transform: rotate(180deg);

-moz-transform: rotate(180deg);

-ms-transform: rotate(180deg);

-o-transform: rotate(180deg);

transform: rotate(180deg);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值