微信小程序音乐播放器页面渲染的方法(微信小程序,开发技术)

时间:2024-05-05 21:13:08 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

    %E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8%E9%A1%B5%E9%9D%A2%E6%B8%B2%E6%9F%93%E7%9A%84%E6%96%B9%E6%B3%95

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

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

.list-top {

position: relative;

height: 100%;

}

.list-top::after {

content: " ";

display: block;

padding-top: 100%;

}

.top-info {

position: absolute;

bottom: 0;

width: 100%;

z-index: 3;

}

.top-img {

width: 100%;

height: 100%;

position: absolute;

}

.top-info-inner {

display: -webkit-box;

-webkit-box-align: center;

margin: 0 15px 25px;

color: #fff;

}

.top-info-text {

-webkit-box-flex: 1;

margin-right: 10px;

}

.top-info-title {

font-size: 24px;

line-height: 36px;

white-space: nowrap;

overflow: hidden;

}

.top-info-base {

font-size: 14px;

line-height: 20px;

}

复制代码

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

  

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

.tl-top-b {

position: absolute;

bottom: 0;

width: 100%;

background-image: -webkit-linear-gradient(top,transparent,currentColor 80%);

}

.tl-top-b::after {

content: " ";

display: block;

padding-top: 60%;

}

复制代码

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

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

.tl-top-play {

position: relative;

display: block;

width: 42px;

height: 42px;

margin-left: 10px;

border: solid 3px;

border-radius: 999px;

}

.tl-top-play::after {

content: " ";

position: absolute;

left: 50%;

top: 50%;

margin-top: -10px;

margin-left: -5px;

display: inline-block;

vertical-align: middle;

width: 0;

height: 0;

border-style: solid;

border-width: 10px 16px;

border-color: transparent transparenttransparent #fff;

}

复制代码

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

//加载网络请求函数

var MusicService = require('../../services/music');

//获取应用实例

var app = getApp();

Page({

data: {

// text:"这是一个页面"

songList: [],

imgUrl: '',

id: 0,

topinfo: {},

update_time: '',

},

onLoad: function (options) {

// 页面初始化 options为页面跳转所带来的参数

var self = this;

var id = app.globalData.topListId;

this.setData({

id: id

});

MusicService.getTopListInfo(id, this.getTopListCallback)

},

})

复制代码

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

getTopListCallback: function (data) {

var imgUrl = data.topinfo.pic_album;

this.setData({

topinfo: data.topinfo,

update_time: data.update_time

});

this.setSongList(data.songlist);

},

复制代码

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

setSongList: function (songs) {

var list = [];

for (var i = 0; i < songs.length; i++) {

var item = songs[i];

var song = {};

var album = {};

album.mid = item.data.albummid

album.id = item.data.albumid

album.name = item.data.albumname;

album.desc = item.data.albumdesc

song.id = item.data.songid;

song.mid = item.data.songmid;

song.name = item.data.songname;

song.title = item.data.songorig;

song.subTitle = '';

song.singer = item.data.singer;

song.album = album;

song.time_public = item.time_public;

song.img = 'http://y.gtimg.cn/music/photo_new/T002R150x150M000' + album.mid + '.jpg?max_age=2592000'

list.push(song);

}

this.setData({

songList: list

})

}

复制代码

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

mainTopTap: function (e) {

var list = this.data.songList;

app.setGlobalData({ //使用全局变量playList来保存我们当前的list

playList: list,

playIndex: 0 //表示从第一首歌曲开始播放

});

wx.navigateTo({

url: '../play/play' //跳转到播放页

});

},

musicItemTap: function (e) {

var dataSet = e.currentTarget.dataset;

var index = dataSet.index; //获取点击的item的序号

var list = this.data.songList;

app.setGlobalData({

playList: list,

playIndex: index //从点击歌曲开始播放

});

wx.navigateTo({

url: '../play/play'

});

},

本文:微信小程序音乐播放器页面渲染的方法的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:小程序如何实现多折叠展开菜单下一篇:

5 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18