跳到主要内容

滑动容器 ScrollView

滑动容器,提供类似于小程序 ScrollView 的能力。

安装使用

import { TiScrollView } from '@titian-design/mobile-react';

用法示例

基础用法

import './index.less';

const App: React.FC = () => {
const upper = () => {
console.log("到达头部");
};
const lower = () => {
console.log("到达底部");
};

const scroll = () => {
console.log("滚动");
};

return (
<div className="scroll-view-page">
<div className="page-section">
<div className="page-section-title">
<span>Vertical Scroll</span>
<p>纵向滚动</p>
</div>
<div className="page-section-spacing">
<TiScrollView
scroll-y
onScrolltoupper={upper}
onScrolltolower={lower}
onTiScroll={scroll}
>
<div id="demo1" className="scroll-view-item demo-text-1" />
<div id="demo2" className="scroll-view-item demo-text-2" />
<div id="demo3" className="scroll-view-item demo-text-3" />
</TiScrollView>
</div>
</div>

<div className="page-section">
<div className="page-section-title">
<span>Horizontal Scroll</span>
<p>横向滚动</p>
</div>
<div className="page-section-spacing">
<TiScrollView
scroll-x
extStyle="width: 100%"
onTiScroll={scroll}
onScrolltoupper={upper}
onScrolltolower={lower}
>
<div id="demo1" className="scroll-view-item-h demo-text-1" />
<div id="demo2" className="scroll-view-item-h demo-text-2" />
<div id="demo3" className="scroll-view-item-h demo-text-3" />
</TiScrollView>
</div>
</div>
</div>
)
}

TiScrollView API

属性 Properties

属性类型默认值必填说明备注
scrollXbooleanfalse允许横向滚动-
scrollYbooleanfalse允许纵向滚动-
upperThresholdnumber | string2px距顶部/左边多远时,触发 scrolltoupper 事件-
lowerThresholdnumber | string2px距底部/右边多远时,触发 scrolltolower 事件-
scrollTopnumber | string-设置竖向滚动条位置-
scrollLeftnumber | string-设置横向滚动条位置-
scrollIntoViewstring-值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素-

事件 Events

名称参数列表说明备注
onScrolltoupper(e: CustomEvent) => void滚动到顶部/左边时触发-
onScrolltolower(e: CustomEvent) => void滚动到底部/右边时触发-
onTiScroll(e: CustomEvent) => void滚动时触发-

CSS 变量 CSS Variables

变量默认值说明备注
--scroll-view-widthauto宽度-
--scroll-view-heightauto高度-
--scroll-view-padding-v0上下 padding 间距-
--scroll-view-padding-h0左右 padding 间距-
--scroll-view-min-widthinitial最小宽度-
--scroll-view-max-widthinitial最大宽度-
--scroll-view-min-heightinitial最小高度-
--scroll-view-max-heightinitial最大高度-
--scroll-view-virtual-displayinline-block组件根节点 display 属性-
--scroll-view-virtual-positionrelative组件根节点 position 属性-