当前位置:网站首页>使用scroll-view实现滑块视图可能遇到的问题及其解决方法
使用scroll-view实现滑块视图可能遇到的问题及其解决方法
2022-07-01 03:49:00 【richest_qi】
小程序项目
代码相关的主要文件有:
- app.json
- pages/index/index.wxml
- pages/index/index.wxss
- pages/index/index.js
app.json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#971a22",
"navigationBarTitleText": "首页",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/index/index.wxml
<view class="indexContainer">
<view class="recommendSongContainer">
<view class="header">
<view class="title">推荐歌单</view>
<view>
<text class="desc">邂逅你的真爱歌单</text>
<text class="btn">></text>
</view>
</view>
<scroll-view class="recommendSongList" enable-flex scroll-x>
<view class="recommendItem" wx:for="{
{list}}" wx:key="id">
<image src="{
{item.picUrl}}"></image>
<view class="name">{
{item.title}}</view>
</view>
</scroll-view>
</view>
<view class="newSongContainer">
<view class="header">
<view class="title">新歌速递</view>
<view>
<text class="desc">更多鲜乐更多快落</text>
<text class="btn">></text>
</view>
</view>
</view>
<view class="newDiscContainer">
<view class="header">
<view class="title">新碟上架</view>
<view>
<text class="desc">魔力新碟好听到爆</text>
<text class="btn">></text>
</view>
</view>
</view>
</view>
pages/index/index.wxss
.indexContainer{
padding: 0 20rpx;
}
.header{
display: flex;
justify-content: space-between;
align-items: center;
margin: 20rpx 0;
}
.header .title{
font-weight: bold;
}
.header .desc{
font-size: 24rpx;
color: #333;
padding: 0 20rpx;
}
.header .btn{
font-size: 24rpx;
padding: 0 10rpx;
background: #eee;
color: #888;
border-radius: 6rpx;
}
.recommendSongList{
display: flex;
}
.recommendSongList image{
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
margin-right: 10rpx;
}
.recommendSongList .name{
font-size: 26rpx;
display: -webkit-box;
overflow: hidden;
text-overflow:ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
pages/index/index.js
Page({
data:{
list:[]
},
onLoad(){
this.getDataFromServer();
},
getDataFromServer(){
const result = [
{
id: 494479726, picUrl: "https://p2.music.126.net/58ox3zVEmosSrdLaKj6x5w==/109951162827155600.jpg", title: "后摇MV | 原来后摇也能视觉化"},
{
id: 135595185, picUrl: "https://p2.music.126.net/11ZHf0G9FQzWNi-8sFzCmw==/109951164541050373.jpg", title: "Acid Jazz酸爵士—爵士乐中的“酸性”融合"},
{
id: 114846926, picUrl: "https://p2.music.126.net/GTf1b1G2dAs1SleurIfcJg==/3399689953594431.jpg", title: "歌名后缀大科普"},
{
id: 113780871, picUrl: "https://p2.music.126.net/qxUWSKhrd1UWME8oAYTMFQ==/109951164497486331.jpg", title: "「Cool Jazz」冷爵士让你全身心放松"},
{
id: 2962407224, picUrl: "https://p2.music.126.net/NW1GEN3sruiLpT4AZrdDFw==/109951165669533032.jpg", title: "『英伦女声』遗世而独立的不列颠玫瑰"},
{
id: 2107922801, picUrl: "https://p2.music.126.net/b--QkIcFfdxz_DryW55ZfA==/109951163165101034.jpg", title: "声光美学 I 经典电影中的古典配乐集"},
{
id: 78669437, picUrl: "https://p2.music.126.net/AfN_yyi-fQe8POTMKJFjAA==/7957165650297535.jpg", title: "美剧中的神级插曲"},
{
id: 3116763088, picUrl: "https://p2.music.126.net/MSom1XSXqt5K9ArZlJ29CQ==/109951164608648583.jpg", title: "音乐的力量 I 文艺复兴时期的世俗情歌"},
{
id: 101354498, picUrl: "https://p2.music.126.net/dmj9iqz8MsD_sCd1xBF0WA==/7918682744429845.jpg", title: "时尚运动•必备节奏"},
{
id: 739403485, picUrl: "https://p2.music.126.net/RPilW2ADtU91CK3qkVPizA==/18720284976441185.jpg", title: "弦外有声——活力小提琴"}
]
this.setData({
list:result})
}
})
问题描述及解决方法
- 问题描述
scroll-view横向滚动后,其高度却很大,导致其后的元素几乎排至页面底部,如下图所示。
- 解决方法
给scroll-view设置指定高度,如height: 280rpx;,即可解决以上问题。
.recommendSongList{
display: flex;
height: 280rpx; /*指定scroll-view的高度*/
}
- 修改后的效果

相关链接
边栏推荐
- Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
- What happens when a function is called before it is declared in C?
- 166. fractions to decimals
- 389. 找不同
- Database DDL (data definition language) knowledge points
- Pytorch training deep learning network settings CUDA specified GPU visible
- 8. 字符串转换整数 (atoi)
- Idea plug-in backup table
- bootsrap中的栅格系统
- [EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
猜你喜欢
![[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes](/img/be/325f78dee744138a865c13d2c20475.png)
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes

【TA-霜狼_may-《百人计划》】1.3纹理的秘密

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算

Pytorch training deep learning network settings CUDA specified GPU visible

陈宇(Aqua)-安全-&gt;云安全-&gt;多云安全
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET

Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)

Download and installation configuration of cygwin

Unexpected token o in JSON at position 1 ,JSON解析问题

283.移动零
随机推荐
有效的 @SuppressWarnings 警告名称
All in one 1086: Jiaogu conjecture
Network metering - application layer
392. judgment subsequence
互联网行业最佳产品开发流程 推荐!
PageObject模式解析及案例
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
Database DDL (data definition language) knowledge points
【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
8. string conversion integer (ATOI)
Unexpected token o in JSON at position 1, JSON parsing problem
Error: plug ins declaring extensions or extension points must set the singleton directive to true
Appium自动化测试基础--补充:C/S架构和B/S架构说明
[party benefits] jsonobject to string, leave blank
What happens when a function is called before it is declared in C?
72. edit distance
409. longest palindrome