碼上歡樂
首頁
榜單
標簽
關於
搜索
相關內容
簡體
繁體
vue 文字模塊實現超出行數展開收縮
本文轉載自
查看原文
2020-12-26 12:02
1110
vue
是一套用於構建用戶界面的漸進式框架。
vue
被設計為可以自底向上逐層應用。
vue
的核心庫只關注視圖層,不僅易於上手,還便於與第三方庫或既有項目整合。另一方面,當與現代化的工具鏈以及各種支持類庫結合使用時,
vue
也完全能夠為復雜的單頁應用提供驅動。
vue
(讀音 /vjuː/,類似於 view) 是一套用於構建用戶界面的漸進式框架。與其它大型框架不同的是,Vue 被設計為可以自底向上逐層應用。Vue 的核心庫只關注視圖層,不僅易於上手,還便於與第三方庫或既有項目整合。另一方面,當與現代化的工具鏈以及各種支持類庫結合使用時,Vue 也完全能夠為復雜的單頁應用提供驅動。'
;
if
(
this
.
introduce
!==
longIntroduce
)
{
this
.
showExchangeButton
=
false
;
this
.
showTotal
=
true
;
this
.
introduce
=
longIntroduce
;
}
},
tryShort
()
{
let shortIntroduce
=
'Vue (讀音 /vjuː/,類似於 view) 是一套用於構建用戶界面的漸進式框架。'
;
if
(
this
.
introduce
!==
shortIntroduce
)
{
this
.
showExchangeButton
=
false
;
this
.
showTotal
=
true
;
this
.
introduce
=
shortIntroduce
;
}
}
},
watch
:
{
'introduce'
:
function
()
{
this
.
$nextTick
(
function
()
{
console
.
log
(
'nextTick'
);
// 判斷介紹是否超過四行
let rem
=
parseFloat
(
this
.
getRem
());
console
.
log
(
'watch 中的rem'
,
rem
);
if
(!
this
.
$refs
.
desc
)
{
console
.
log
(
'desc null'
);
return
;
}
let descHeight
=
window
.
getComputedStyle
(
this
.
$refs
.
desc
).
height
.
replace
(
'px'
,
''
);
console
.
log
(
'descHeight:'
+
descHeight
);
console
.
log
(
'如果 descHeight 超過'
+
(
5.25
*
rem
)
+
'就要顯示展開按鈕'
);
if
(
descHeight
>
5.25
*
rem
)
{
console
.
log
(
'超過了四行'
);
// 顯示展開收起按鈕
this
.
showExchangeButton
=
true
;
this
.
exchangeButton
=
true
;
// 不是顯示所有
this
.
showTotal
=
false
;
}
else
{
// 不顯示展開收起按鈕
this
.
showExchangeButton
=
false
;
// 沒有超過四行就顯示所有
this
.
showTotal
=
true
;
console
.
log
(
'showExchangeButton'
,
this
.
showExchangeButton
);
console
.
log
(
'showTotal'
,
this
.
showTotal
);
}
}.
bind
(
this
));
}
}
};
</script>
<style
lang
=
"less"
scoped
rel
=
"stylesheet/less"
>
.
top
-
prove
{
height
:
100px
;
width
:
100
%;
background
:
#dddddd;
text
-
align
:
center
;
line
-
height
:
100px
;
}
.
total
-
introduce
{
height
:
auto
;
overflow
:
hidden
;
font
-
size
:
14px
;
color
:
#434343;
margin
:
10px
;
.
intro
-
content
{
.
merchant
-
desc
{
width
:
100
%;
line
-
height
:
21px
;
}
}
.
unfold
{
display
:
block
;
z
-
index
:
11
;
float
:
right
;
width
:
40px
;
height
:
21px
;
p
{
margin
:
0
;
line
-
height
:
21px
;
color
:
#7fbe87;
}
}
}
.
detailed
-
introduce
{
font
-
size
:
14px
;
color
:
#434343;
position
:
relative
;
overflow
:
hidden
;
margin
:
10px
;
.
intro
-
content
{
// 最大高度設為4倍的行間距
max
-
height
:
84px
;
line
-
height
:
21px
;
word
-
wrap
:
break
-
word
;
/*強制打散字符*/
word
-
break
:
break
-
all
;
background
:
#ffffff;
/*同背景色*/
color
:
#ffffff;
overflow
:
hidden
;
.
merchant
-
desc
{
width
:
100
%;
line
-
height
:
21px
;
}
&:
after
,
// 這是展開前實際顯示的內容
&:
before
{
content
:
attr
(
title
);
position
:
absolute
;
left
:
0
;
top
:
0
;
width
:
100
%;
color
:
#434343
// overflow: hidden;
}
// 把最后最后一行自身的上面三行遮住
&:
before
{
display
:
block
;
overflow
:
hidden
;
z
-
index
:
1
;
max
-
height
:
63px
;
background
:
#ffffff;
}
&:
after
{
display
:
-
webkit
-
box
;
-
webkit
-
box
-
orient
:
vertical
;
overflow
:
hidden
;
height
:
81px
;
/*截取行數*/
-
webkit
-
line
-
clamp
:
4
;
text
-
overflow
:
ellipsis
;
-
webkit
-
box
-
sizing
:
border
-
box
;
box
-
sizing
:
border
-
box
;
/*行首縮進字符數,值為[(截取行數-1)*尾部留空字符數]*/
text
-
indent
:
-
12em
;
/*尾部留空字符數*/
padding
-
right
:
4em
;
}
.
unfold
{
z
-
index
:
11
;
width
:
40px
;
height
:
21px
;
outline
:
0
;
position
:
absolute
;
right
:
0
;
bottom
:
0
;
p
{
margin
:
0
;
line
-
height
:
21px
;
color
:
#7fbe87;
}
}
}
}
.
bottom
-
prove
{
height
:
100px
;
width
:
100
%;
background
:
#dddddd;
text
-
align
:
center
;
line
-
height
:
100px
;
}
.
change
-
buttom
{
font
-
size
:
14px
;
color
:
#2371be;
.
long
{
text
-
align
:
21px
;
text
-
align
:
center
;
height
:
21px
;
}
.
short
{
text
-
align
:
21px
;
text
-
align
:
center
;
height
:
20px
;
}
}
</style>
×
免責聲明!
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。
猜您在找
UILabel計算行數,文字展開,收縮功能實現
vue-文字塊收縮與展開功能
vue 實現超出兩行顯示展開收起功能(行數可自定義)
vue實現collapse手風琴組件展開和收縮
js 實現內容的展開和收縮
微信小程序 - 文字收縮與展開
JS實現段落的收縮與展開
vue實現顯示兩行,溢出顯示省略號,點擊實現展開收縮效果
【iOS系列】-UITableViewCell的展開與收縮的實現思路
利用js實現圖片展開與收縮
粵ICP備18138465號
© 2018-2025 CODEPRJ.COM