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

相关链接
边栏推荐
- 208. implement trie (prefix tree)
- What does ft mean in the data book table
- 165. 比较版本号
- 静态库使用MFC和共享库使用MFC的区别
- 10. regular expression matching
- 报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
- Volley parsing data shows networking failure
- Go learning --- unit test subtest
- 【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
- 谷粒学院微信扫码登录过程记录以及bug解决
猜你喜欢

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

C语言的sem_t变量类型

Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)

Implement pow (x, n) function

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

Download and installation configuration of cygwin

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

431. 将 N 叉树编码为二叉树 DFS

Millet College wechat scanning code login process record and bug resolution

Use of JMeter counters
随机推荐
The programmer's girlfriend gave me a fatigue driving test
MFC window scroll bar usage
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
10、Scanner. Next() cannot read spaces /indexof -1
You cannot right-click F12 to view the source code solution on the web page
快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
Addition without addition, subtraction, multiplication and division
187. repeated DNA sequences
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
【TA-霜狼_may-《百人计划》】1.2.1 向量基础
C语言的sem_t变量类型
陈宇(Aqua)-安全-&gt;云安全-&gt;多云安全
线程常用方法与守护线程
Database DDL (data definition language) knowledge points
【TA-霜狼_may-《百人计划》】1.3纹理的秘密
Analysis and case of pageobject mode
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
Deep learning | rnn/lstm of naturallanguageprocessing
The difference between MFC for static libraries and MFC for shared libraries