更新记录

1.0.1(2024-06-19)

更新使用说明文挡

1.0.0(2024-06-19)

新增


平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.1.0 × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × ×

hbxw-scrollview组件

介绍

方了更方便使用scrollView实现局部滚动器,基于scrolView封装的局部滚动器 默认的scrollView如果要做竖向滚动需要指定高度,hbxw-scrollview只要按指定方式使用,内部会自动设置为父容器的高度 横向滚动需要添加white-space: nowrap,hbxw-scrollview如果判断到当前是横向滚动会自动添加该样式

使用示例

推荐先直接复制示例代码到工程中看效果了解下使用方法再投入项目使用。


<template>
    <view class="conainer">
        <view class="header">头部</view>
        <text class="test-title">竖向滚动:</text>
        <view class="scroll-vertical">
            <hbxw-scrollview 
                scroll-y 
                style="display: flex;flex-direction: column;flex:1;"
                @scrolltolower="scrolltolowerVertical"
            >
                <view class="test-item">1</view>
                <view class="test-item">2</view>
                <view class="test-item">3</view>
                <view class="test-item">4</view>
                <view class="test-item">5</view>
                <view class="test-item">6</view>
                <view class="test-item">7</view>
                <view class="test-item">8</view>
            </hbxw-scrollview>
        </view>
        <text class="test-title">横向滚动:</text>
        <view class="scroll-transverse">
            <hbxw-scrollview 
                scroll-x 
                style="display: flex;flex-direction: column;flex:1;"
                @scrolltolower="scrolltolowerTransverse"
            >
                <view class="test-item-wrap">
                    <view class="test-item0">1</view>
                    <view class="test-item0">2</view>
                    <view class="test-item0">3</view>
                    <view class="test-item0">4</view>
                    <view class="test-item0">5</view>
                    <view class="test-item0">6</view>
                    <view class="test-item0">7</view>
                    <view class="test-item0">8</view>
                </view>
            </hbxw-scrollview>
        </view>
        <view class="footer">底部</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {

            }
        },
        methods: {
            scrolltolowerVertical(e) {
                console.log('----  竖向滚动到底了  ----:', e);
            },
            scrolltolowerTransverse(e) {
                console.log('----  横向滚动到最右边了  ----:', e);
            }
        }
    }
</script>
<style>
    page{
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
</style>
<style lang="scss" scoped>
.conainer{
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.header{
    width:100%;
    height: 86rpx;
    text-align: center;
    font-size: 36rpx;
    color: white;
    background-color: red;
    flex: none;
}
.footer{
    width:100%;
    height: 68rpx;
    text-align: center;
    font-size: 36rpx;
    color: white;
    background-color: blue;
    flex: none;
}
.test-title{
    flex: none;
}
.test-item{
    width: 100%;
    height: 168rpx;
    margin-bottom: 20rpx;
    text-align: center;
    line-height: 168rpx;
    color: white;
    background-color: green;
}
.test-item-wrap{
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    width: 140%;
    height: 100%;
    .test-item0{
        flex: 1;
        height: 168rpx;
        margin-right: 20rpx;
        text-align: center;
        line-height: 168rpx;
        color: white;
        background-color: green;
    }
}
.scroll-vertical{
    display: flex;
    flex:1;
}
.scroll-transverse{
    flex:1;
    display: flex;
}
</style>

注:组件在使用中请添加style="display: flex;flex-direction: column;flex:1;" 使用技巧:此示例是在弹性盒模型中使用,scrollView父组是一个flex元素,在弹性盒模型中会自动适应高度,scrollView会在mounted生命钩子中获取父级元素的高度用于自身的高度

API

Props

属性名 类型 默认值 必填 说明
scrollX Boolean false 允许横向滚动
scrollY Boolean false 允许纵向滚动
upperThreshold Number/String 50 距顶部/左边多远时(单位px),触发 scrolltoupper 事件
lowerThreshold Number/String 50 距底部/右边多远时(单位px),触发 scrolltolower 事件
scrollIntoView String undefined 值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素
scrollTop String undefined 设置竖向滚动条位置
scrollLeft String undefined 设置横向滚动条位置

Events

事件名 说明 返回值
scrolltolower 滚动到底/右触发的事件 事件对象event
scrolltoupper 滚动到顶/左触发的事件 事件对象event
scroll 滚动时触发的事件 事件对象event event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}

注:暴露了scrollView使用率高的参数和方法,详见官方文挡:scrollView

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问