html css js 實現展開和收起的操作方法
wxml 代碼
<view class="business-text {{ isExpanding ? 'block' : 'none' }}">小程序用 js + css +html 實現展開和收起的操作方法,實例代碼簡單,實現方式有很多種。小程序用 js + css +html 實現展開和收起的操作方法,實例代碼簡單,實現方式有很多種。</view>
<view class="business-btn" bindtap="handleExpandingChange">{{isExpanding ? "收起" : "展開"}} <text class="horn {{ isExpanding ? 'block' : 'none' }}"></text></view>
wxss 代碼
.business-text{
margin: 0 auto;
width: 696rpx;
font-size: 28rpx;
color: #3F4552;
font-family: 'PingFangSC-Regular';
overflow: hidden;
text-align: justify;
}
/*
1.默認設置高度 隱藏其它
2.設置兩行末尾顯示...
*/
.business-text.none {
height: 40rpx;
/* -webkit-line-clamp: 2;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical; */
/* 從上向下垂直排列子元素 */
}
/*
顯示方式以下三種block都可以實現
*/
.business-text.block {
display: block;
/* -webkit-line-clamp: 0; */
/* overflow: visible; */
}
.business-btn{
margin: 28rpx auto 16rpx;
width: 84rpx;
height: 50rpx;
line-height: 50rpx;
text-align: center;
border: 1px solid #eee;
border-radius: 28rpx;
font-size: 26rpx;
font-family: 'PingFangSC-Regular';
color: #C0C6D6;
position: relative;
padding: 0 55rpx 0 48rpx;
}
.business-btn .horn{
width:0;
height:0;
position: absolute;
top: 50%;
left: 66%;
transform: translateY(-50%);
}
.business-btn .horn.none{
border-left: 8rpx solid transparent;
border-right: 8rpx solid transparent;
border-top: 12rpx solid #b9c0d0;
}
.business-btn .horn.block{
border-left: 8rpx solid transparent;
border-right: 8rpx solid transparent;
border-bottom: 12rpx solid #b9c0d0;
}
js 代碼
data: {
isExpanding: false,
}
/**
* 展開/收起
*/
handleExpandingChange: function() {
this.setData({
isExpanding: !this.data.isExpanding
})
},