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

相关链接
边栏推荐
- Implement pow (x, n) function
- [ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
- 168. Excel表列名称
- 熊市下的Coinbase:亏损、裁员、股价暴跌
- 【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
- 241. Design priorities for operational expressions
- 283.移动零
- Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
- [untitled] Li Kou 496 Next larger element I
- How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
猜你喜欢

C语言的sem_t变量类型
![[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation

陈宇(Aqua)-安全-&gt;云安全-&gt;多云安全

线程常用方法与守护线程

Web components series (VIII) -- custom component style settings

Deep learning | rnn/lstm of naturallanguageprocessing

Usage of AfxMessageBox and MessageBox

Appium fundamentals of automated testing - basic principles of appium
![[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation](/img/49/173b1f1f379faa28c503165a300ce0.png)
[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation

Addition without addition, subtraction, multiplication and division
随机推荐
Network metering - application layer
静态库使用MFC和共享库使用MFC的区别
389. 找不同
283.移动零
208. implement trie (prefix tree)
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
165. 比较版本号
171. Excel 表列序号
Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
Huawei simulator ENSP - hcip - Hybrid Experiment 2
【快捷键】
206.反转链表
8. string conversion integer (ATOI)
5. [WebGIS practice] software operation - service release and permission management
Redis(七)优化建议
浏览器顶部loading(来自知乎)
[party benefits] jsonobject to string, leave blank
JMeter学习笔记2-图形界面简单介绍
Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly