137-3385-8848(同微信)

微信小程序音乐播放器,音乐播放器小程序制作步骤(页面渲染)

2022-04-21 管理员

  页面渲染

  

  为了解决这个问题,我们给图片添加一个渐变的遮罩,就像图10-8那样,这样到达文字部分时,背景就变成了黑色,不会影响文字的显示,而且达到了由图片到底下列表颜色渐变的效果,非常美观。

  这个效果主要靠我们的格式文件实现,我们先写我们熟悉的部分。

  1. .list-top {
  2.     position: relative;
  3.     height: 100%;
  4. }
  5. .list-top::after {         
  6.     content: " ";
  7.     display: block;
  8.     padding-top: 100%;
  9. }
  10. .top-info {
  11.     position: absolute;
  12.     bottom: 0;
  13.     width: 100%;
  14.     z-index: 3;
  15. }
  16. .top-img {
  17.     width: 100%;
  18.     height: 100%;
  19.     position: absolute;
  20. }
  21.  
  22. .top-info-inner {
  23.     display: -webkit-box;
  24.     -webkit-box-align: center;
  25.     margin: 0 15px 25px;
  26.     color: #fff;
  27. }
  28.  
  29. .top-info-text {
  30.     -webkit-box-flex: 1;
  31.     margin-right: 10px;
  32. }
  33. .top-info-title {
  34.     font-size: 24px;
  35.     line-height: 36px;
  36.     white-space: nowrap;
  37.     overflow: hidden;
  38. }
  39. .top-info-base {
  40.     font-size: 14px;
  41.     line-height: 20px;
  42. }
复制代码

 

  “::after”表示在“.list-top”后边添加,为了是在不修改布局文件的情况下,添加视图以达到美化的效果。

  

  我们需要添加的遮罩为布局里“top—back”这部分,格式文件为:

  1. .tl-top-b {
  2.     position: absolute;
  3.     bottom: 0;
  4.     width: 100%;
  5.     background-image: -webkit-linear-gradient(top,transparent,currentColor 80%);
  6. }
  7. .tl-top-b::after {
  8.     content: " ";
  9.     display: block;
  10.     padding-top: 60%;
  11. }
复制代码

 

  -webkit-linear-gradient(top,transparent,currentColor 80%)这行代码为我们建立了线性渐变的效果,这样我们的图片底部就会出现渐变为黑色的效果了。

  剩下播放按钮的样式,这里因为用到了渐变的遮罩和背景图,为了达到最好的效果,这个按钮就不能用图片来显示了,我们使用代码来创建一个播放按钮。

  1. .tl-top-play {
  2.     position: relative;
  3.     display: block;
  4.     width: 42px;
  5.     height: 42px;
  6.     margin-left: 10px;
  7.     border: solid 3px;
  8.     border-radius: 999px;
  9. }
  10. .tl-top-play::after {
  11.     content: " ";
  12.     position: absolute;
  13.     left: 50%;
  14.     top: 50%;
  15.     margin-top: -10px;
  16.     margin-left: -5px;
  17.     display: inline-block;
  18.     vertical-align: middle;
  19.     width: 0;
  20.     height: 0;
  21.     border-style: solid;
  22.     border-width: 10px 16px;
  23.     border-color: transparent transparent  transparent #fff;
  24. }
复制代码

 

  视图建立完毕,开始为视图填充数据。

  1. //加载网络请求函数
  2. var MusicService = require('../../services/music');
  3. //获取应用实例
  4. var app = getApp();
  5.  
  6. Page({
  7.     data: {
  8.         // text:"这是一个页面"
  9.         songList: [],
  10.         imgUrl: '',
  11.         id: 0,
  12.         topinfo: {},
  13.         update_time: '',
  14.     },
  15.     onl oad: function (options) {
  16.         // 页面初始化 options为页面跳转所带来的参数
  17.         var self = this;
  18.         var id = app.globalData.topListId;
  19.         this.setData({
  20.             id: id
  21.         });
  22.         MusicService.getTopListInfo(id, this.getTopListCallback)
  23.     },
  24. })
复制代码

 

  这里我们获取了保存于全局变量里的topListId(即我们点击的排行分类的ID),然后使用这个ID请求网络。

  1. getTopListCallback: function (data) {
  2.         var imgUrl = data.topinfo.pic_album;
  3.         this.setData({
  4.             topinfo: data.topinfo,
  5.             update_time: data.update_time
  6.         });
  7.         this.setSongList(data.songlist);
  8.     },
复制代码

 

  使用回调函数为我们的data赋值之后,这里调用了setSongList这个方法,通过这个方法我们把返回数据里我们需要的内容保存到songList里。

  1. setSongList: function (songs) {
  2.         var list = [];
  3.         for (var i = 0; i < songs.length; i++) {
  4.             var item = songs[i];
  5.             var song = {};
  6.             var album = {};
  7.  
  8.             album.mid = item.data.albummid
  9.             album.id = item.data.albumid
  10.             album.name = item.data.albumname;
  11.             album.desc = item.data.albumdesc
  12.  
  13.             song.id = item.data.songid;
  14.             song.mid = item.data.songmid;
  15.             song.name = item.data.songname;
  16.             song.title = item.data.songorig;
  17.             song.subTitle = '';
  18.             song.singer = item.data.singer;
  19.             song.album = album;
  20.             song.time_public = item.time_public;
  21.             song.img = 'http://y.gtimg.cn/music/photo_new/T002R150x150M000' + album.mid + '.jpg?max_age=2592000'
  22.             list.push(song);
  23.         }
  24.         this.setData({
  25.             songList: list
  26.         })
  27.     }
复制代码

 

  最好完成此页面里的点击事件:

  1. mainTopTap: function (e) {
  2.         var list = this.data.songList;
  3.         app.setGlobalData({                //使用全局变量playList来保存我们当前的list
  4.             playList: list,
  5.             playIndex: 0                    //表示从第一首歌曲开始播放
  6.         });
  7.         wx.navigateTo({
  8.             url: '../play/play'            //跳转到播放页
  9.         });
  10.     },
  11.     musicItemTap: function (e) {
  12.         var dataSet = e.currentTarget.dataset;
  13.         var index = dataSet.index;                //获取点击的item的序号
  14.         var list = this.data.songList;
  15.         app.setGlobalData({
  16.             playList: list,
  17.             playIndex: index                      //从点击歌曲开始播放
  18.         });
  19.         wx.navigateTo({
  20.             url: '../play/play'
  21.         });
  22.     },
复制代码

 

  上一节:微信小程序小白项目开发案例之音乐播放器-获取列表页数据

  下一节:微信小程序小白项目开发案例之音乐播放器-完成相似页面

  

上一篇:微信小程序音乐播放器,音乐播放器小程序制作步骤(音乐排行榜)
下一篇:微信小程序音乐播放器,音乐播放器小程序制作步骤(相似页面)
相关资讯 Releva ntnews
解决方案 Solutions
相关热点 Hot spot
郑州做排名中正确使用关键词优化的方法
  1. 我们的优势
  2. 我们的实力
  3. 选择我们的理由
咨询电话(微信同号)

137-3385-8848(同微信)

豫ICP备16014343号-1

Copyright © 2017-2022 版权所有 酷微科技 Rights Reserved

电话咨询 在线咨询 服务项目 SEO优化