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.根據內容判斷狀態
<div class="reply-comtent marginmain" v-if="item.toggleShowDes" :index="comIndex">
[[ item.content ]]
<div class="flex flex-align-center height4" @click="spread(item,comIndex,false)">
<div class="more-operation collect flex flex-align-center ">
<span>收起全部</span>
<img class="retract" src="/images/wrong/down.png" alt="" width="" height="">
</div>
</div>
</div>
<!--省略介紹-->
<div class="relative intro-wrap1 reply-comtent marginmain" v-else :index="comIndex">
<p :class="'font-text-shallow'+' '+ 'intro' + ' '+ (item.ifMore == true?'des1':'')">
[[ item.content ]]
</p>
<div class="flex flex-align-center height4" v-if="item.ifMore && !item.toggleShowDes" @click="spread(item,comIndex,true)">
<div class="more-operation open flex flex-align-center ">
<span>展開全部</span>
<img class="" src="/images/wrong/down.png" alt="" width="" height="">
</div>
</div>
</div>
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);
}
相關文章
- 文字超長,實現展開收起功能...
- JavaScript 實現全部選中與全不選JavaScript
- Vue 全家桶 + Express 實現的部落格(後端API全部自己手寫)VueExpress後端API
- iOS開發中QQ好友列表下拉顯示全部好友實現思路iOS
- DevOps 如何幫助實現安全部署dev
- JavaScript段落展開收起效果JavaScript
- 實現5G的全部潛力需要融合網路
- js實現的替換字串中的全部指定內容JS字串
- 陣列全部整理陣列
- sqlserver 全部索引重建SQLServer索引
- 基於JQuery的自定義樹形選單表格,實現展開、收起效果jQuery
- Android自定義View——從零開始實現可展開收起的水平選單欄AndroidView
- 文章點選展開和收起詳解
- 突發奇想!藉助CSS自定義彩色字型來實現多行文字展開收起CSS
- PHP外掛系統的實現(二):獲取全部外掛資訊PHP
- 應用數學的哲學 | 全部物理宇宙全部能由數學理解
- css3多行文字多行文字縮略點選更多展開顯示全部CSSS3
- js中字串全部替換JS字串
- PHP顯示全部錯誤PHP
- mysql全部版本下載地址MySql
- 全部HTML程式碼學習HTML
- 「LeetCode」全部題解LeetCode
- iOS tableviewcell裡點選文字展開與收起功能iOSView
- jQuery點選展開收起程式碼例項jQuery
- Twitter將向科學家開放全部資料
- js控制文字內容過多時候點選展開方式顯示全部內容demoJS
- 為什麼我們放棄使用Kafka Streams實現全部的事件溯源?-MateuszKafka事件
- C++引用全部知識點C++
- Ceph的叢集全部換IP
- Oracle 跟蹤全部使用者Oracle
- SAP Tcode全部中文對照
- 使用java的MultipartFile實現layui官網檔案上傳實現全部示例,java檔案上傳JavaUI
- div以滑動方式展開和收起程式碼
- vue實現 可展開 且 可多選table 元件封裝Vue元件封裝
- View Design 物料市場專案已全部適配 Vue.js 3ViewVue.js
- 3000份水稻重測序資料全部公開
- JavaScript 替換字串全部指定內容JavaScript字串
- 【建議】通知,全部設定已讀