2***@qq.com
2***@qq.com
  • 发布:2024-09-26 00:41
  • 更新:2024-09-26 09:33
  • 阅读:58

uniapp-x里面scroll-view的水平滚动不生效

分类:uni-app x

uniapp-x里面scroll-view的direction水平滚动不生效

在设置scroll-view的direction的值为horizontal并且添加一系列属性后还是不能实现水平滚动

<template>  
    <view class="box" hover-class="boxHover">        
        <view class="inner" hover-class="innerHover" hover-stop-propagation>内部元素</view>  
    </view>  

    <scroll-view direction="horizontal" class="scrollView">  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
        <view class="box">scroll子元素</view>  
    </scroll-view>  
</template>  

<script setup>  
</script>  

<style lang="scss">  
    .scrollView {  
        width: 80%;  
        height: 220px;  
        border: 1px solid red;  
        white-space: nowrap;  
        overflow-x: auto; /* 允许水平滚动 */  
        overflow-y: hidden; /* 隐藏垂直滚动条 */  

        .box {  
            width: 100px;  
            height: 100px;  
            background: green;  
            display: inline-block;  
            margin: 5px;  
        }  
    }  
</style>
2024-09-26 00:41 负责人:无 分享
已邀请:
爱豆豆

爱豆豆 - 办法总比困难多

flex排列方式你没改啊 改一下就flex-direction: row;了

<template>    
    <view class="box" hover-class="boxHover">          
        <view class="inner" hover-class="innerHover" hover-stop-propagation>内部元素</view>    
    </view>    

    <scroll-view direction="horizontal" class="scrollView">    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
        <view class="box">scroll子元素</view>    
    </scroll-view>    
</template>    

<script setup>    
</script>    

<style lang="scss">    
    .scrollView {    
        width: 80%;    
        height: 220px;    
        border: 1px solid red;    
        flex-direction: row;  
        .box {    
            width: 100px;    
            height: 100px;    
            background: green;    
            margin: 5px;    
        }    
    }    
</style>  

要回复问题请先登录注册