微信小程序 27 进度条的动态实现和搜索框、热搜榜的静态搭建

27.1 进度条的动态实现


在这里插入图片描述
在这里插入图片描述

        // 音乐管理者实时播放的进度
        appInstance.globalData.backgroundAudioManager.onTimeUpdate(() => {
            let currentTime = moment(appInstance.globalData.backgroundAudioManager.currentTime * 1000).format('mm:ss');
            if(this.data.isPlay && this.data.song.id == this.data.preMusicId){
                this.setData({
                    currentTime
                });
            }
            // 现在的时间/总时间 = 现在的进度条宽度/总进度条宽度
            // 现在的进度条宽度 = 现在的时间/总时间 * 总进度条宽度
            this.setData({
                currentWidth:appInstance.globalData.backgroundAudioManager.currentTime * 1000/ this.data.durationSS * 450
            })
        });
         // 音乐自然结束的事件
        appInstance.globalData.backgroundAudioManager.onEnded(() => {
            PubSub.publish("switchType","next");// 发送 next 请求
            this.setData({ // 还原进度条的 长度
                currentWidth: 0,
                currentTime: '00:00'
            })
        })

音乐自然结束后,应该播放下一首歌,而这个操作 其实 就是发送一个 publish 就可以做到的。
在这里插入图片描述


27.2 搜索框、热搜榜的静态搭建

{
    "usingComponents": {},
    "navigationBarTitleText": "搜索音乐"
}
<view class="searchContainer">
<!--    头部-->
    <view class="header">
        <view class="searchInput">
            <text class="iconfont icon-search searchIcon"></text>
            <input type="text" placeholder="搜索歌曲" placeholder-class="placeholder"></input>
        </view>
        <text class="cancel">取消</text>
    </view>
<!--热搜榜-->
    <view class="hotContainer">
        <view class="title">热搜榜</view>
<!--        热搜列表-->
        <view class="hotList">
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
            <view class="hotItem">
                <text class="order">1</text>
                <text>偏爱</text>
            </view>
        </view>
    </view>

</view>
/* pages/search/search.wxss */

.searchContainer {
    padding: 0 20rpx;
}

.header {
    display: flex;
    height: 60rpx;
    line-height: 60rpx;
    padding: 10rpx 0;
}

.searchInput {
    position: relative;
    flex: 1;
    background: rgba(237,237,237,0.3);
    border-right: 30rpx;
}

.cancel {
    width: 100rpx;
    text-align: center;
}

.searchIcon {
    position: absolute;
    left: 15rpx;
}

.searchInput input{
    margin-left: 50rpx;
    height: 60rpx;
}

/*h5 新特性之一,可以将 placeholder 设置 class 和 样式*/
.placeholder {
    color: #d43c33;
    font-size: 28rpx;
}

/*热搜榜*/
.hotContainer .title {
    font-size: 28rpx;
    height: 80rpx;
    line-height: 80rpx;
    border-bottom: 1rpx solid #eee;
}

.hotList {
    display: flex;
    flex-wrap: wrap;
}

.hotItem {
    width: 50%;
    height: 80rpx;
    line-height: 80rpx;
    font-size: 26rpx;
}

.hotItem .order {
    margin: 0 10rpx;
}

在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值