当前位置:网站首页>使用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的高度*/
}
- 修改后的效果

相关链接
边栏推荐
- How keil displays Chinese annotations (simple with pictures)
- C语言的sem_t变量类型
- Unexpected token o in JSON at position 1, JSON parsing problem
- Use of JMeter counters
- [TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
- Unity之三维空间多点箭头导航
- Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
- How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
- 这可能是你进腾讯最后的机会了..
- 283.移动零
猜你喜欢

431. 将 N 叉树编码为二叉树 DFS
![[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis](/img/94/99090ea91082a385968e071ef3766c.png)
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis

Huawei simulator ENSP - hcip - Hybrid Experiment 2

Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
![5. [WebGIS practice] software operation - service release and permission management](/img/5d/070e207bd96e60ba1846d644d4fb54.png)
5. [WebGIS practice] software operation - service release and permission management

How keil displays Chinese annotations (simple with pictures)

定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见

25.K个一组翻转链表

431. encode n-ary tree as binary tree DFS

陈宇(Aqua)-安全-&gt;云安全-&gt;多云安全
随机推荐
6. zigzag transformation
【TA-霜狼_may-《百人计划》】1.1 渲染流水线
72. 编辑距离
389. 找不同
5. [WebGIS practice] software operation - service release and permission management
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
214. 最短回文串
浏览器顶部loading(来自知乎)
392. judgment subsequence
Web components series (VIII) -- custom component style settings
What does ft mean in the data book table
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
Unity之三维空间多点箭头导航
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
C语言的sem_t变量类型
【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
Promql select time series
基于Unet的环路滤波