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
})
},
网友评论