<scroll-view class="content" scroll-x="true" style="white-space: nowrap;"> <view class="course-item"> <image src="https://images.clwy.cn/video/course/27/image/a9261f.jpg!thumb" class="image" /> <text class="name"> 简单要死的 Git(GitHub)入门教程 </text> </view> <view class="course-item"> <image src="https://images.clwy.cn/video/course/10/image/2ede85.jpg!thumb" class="image" /> <text class="name"> Node.js 入门 - 使用 Express + Sequelize 实作 API </text> </view> <view class="course-item"> <image src="https://images.clwy.cn/video/course/10/image/2ede85.jpg!thumb" class="image" /> <text class="name"> Node.js 入门 - 使用 Express + Sequelize 实作 API </text> </view> </scroll-view>修改代码使其能滚动
时间: 2024-03-01 11:53:09 浏览: 103
你需要在 CSS 文件中为 `scroll-view` 组件设置一个固定的宽度,才能使其可以横向滚动。以下是一个示例代码,你可以在自己的代码中进行修改:
```
.content {
width: 100%; /* 设置一个固定的宽度,可以是百分比或者像素值 */
white-space: nowrap;
}
.course-item {
display: inline-block;
margin-right: 10px;
}
.image {
width: 100%;
height: 100px;
object-fit: cover;
}
```
注意,`display: inline-block;` 和 `margin-right: 10px;` 是为了让每个课程卡片在同一行中显示,并且之间有一定的间距。`object-fit: cover;` 则是为了让图片按比例缩放,并且填满整个图片框。
相关问题
<scroll-view class="scroll-wrapper" scroll-x scroll-with-animation="true" scroll-into-view="item{{currentTab < 4 ? 0 : currentTab - 3}}"> <view class="navigate-item" id="item{{index}}" wx:for="{{tabList}}" wx:key="index" data-index="{{index}}" bindtap="tabNav"> <view class="names {{currentTab === index ? 'active' : ''}}">{{item.name}}</view> <view class="currtline {{currentTab === index ? 'active' : ''}}" wx:if="{{currentTab === index}}"></view> </view> </scroll-view> <swiper indicator-dots="{{false}}" bindchange="handleSwiper" current="{{currentTab}}"> <block wx:for="{{tabList}}" wx:key="index"> <swiper-item style="overflow: scroll;"> <view class="tab_title">tab{{currentTab+1}}内容</view> <scroll-view scroll-y refresher-enabled refresher-background="#F6F7F8" refresher-triggered="{{isRefresh}}" bindrefresherrefresh="refresherpulling" bindscrolltolower="handleTolower"> <view class="swiper-item" wx:for="{{20}}" wx:key="index">第{{index + 1}}条数据~</view> </scroll-view> </swiper-item> </block> </swiper> 将这段微信小程序代码转化成vue框架下的代码
<template>
<div>
<scroll-view class="scroll-wrapper" scroll-x scroll-with-animation="true" :scroll-into-view="`item${currentTab < 4 ? 0 : currentTab - 3}`">
<view class="navigate-item" :id="`item${index}`" v-for="(item, index) in tabList" :key="index" :data-index="index" @tap="tabNav">
<view class="names" :class="{ active: currentTab === index }">{{item.name}}</view>
<view class="currtline" :class="{ active: currentTab === index }" v-if="currentTab === index"></view>
</view>
</scroll-view>
<swiper :indicator-dots="false" @change="handleSwiper" :current="currentTab">
<swiper-item v-for="(item, index) in tabList" :key="index" style="overflow: scroll;">
<view class="tab_title">tab{{currentTab+1}}内容</view>
<scroll-view scroll-y refresher-enabled refresher-background="#F6F7F8" :refresher-triggered="isRefresh" @refresherrefresh="refresherpulling" @scrolltolower="handleTolower">
<view class="swiper-item" v-for="(item, index) in 20" :key="index">第{{index + 1}}条数据~</view>
</scroll-view>
</swiper-item>
</swiper>
</div>
</template>
<script>
export default {
data() {
return {
currentTab: 0,
isRefresh: false,
tabList: [{ name: 'tab1' }, { name: 'tab2' }, { name: 'tab3' }, { name: 'tab4' }, { name: 'tab5' }]
}
},
methods: {
tabNav(e) {
this.currentTab = e.currentTarget.dataset.index
},
handleSwiper(e) {
this.currentTab = e.detail.current
},
refresherpulling() {
// 下拉刷新
},
handleTolower() {
// 上拉加载更多
}
}
}
</script>
<view class="sticky-box" :style="'top:'+(marTop)+'px;'"> <scroll-view class="scroll-view_H" style="width: 100%;" scroll-x="true" scroll-with-animation :scroll-left="tabsScrollLeft" @scroll="scroll"> <view class="tab nav-bd" id="tab_list"> <view id="tab_item" :class="{ 'active': listActive == index}" class="item" v-for="(item, index) in explosiveMoney" :key="index" > <view class="txt">{{item.name}}</view> <video class="label">{{item.video}}</video> </view> </view> </scroll-view> </view> .sticky-box { /* #ifndef APP-PLUS-NVUE */ display: flex; position: -webkit-sticky; /* #ifdef H5*/ top: var(--window-top); /* #endif */ z-index: 99; flex-direction: row; margin: 0px; background: #f5f5f5; padding: 30rpx 0; }将他修改为只用来显示文字和视频,文字在视频上方,视频和文字居中对齐,一行只显示一个文字或者视频,将多余的代码删除
以下是修改后的代码:
```
<view class="sticky-box">
<scroll-view class="scroll-view_H" style="width: 100%;" scroll-x="true" scroll-with-animation :scroll-left="tabsScrollLeft" @scroll="scroll">
<view class="tab nav-bd" id="tab_list">
<view id="tab_item" :class="{ 'active': listActive == index}" class="item" v-for="(item, index) in explosiveMoney" :key="index">
<view class="txt">{{item.name}}</view>
<video class="label" style="display: block; margin: 0 auto;">{{item.video}}</video>
</view>
</view>
</scroll-view>
</view>
```
这里只保留了文字和视频的显示,文字在视频上方,使用样式 `display: block; margin: 0 auto;` 使视频和文字居中对齐,且一行只显示一个文字或者视频。同时删除了多余的样式代码。
阅读全文