跳到主要内容

滑动容器 ScrollView

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

安装使用

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

用法示例

基础用法

<template>
<div class="scroll-view-page">
<div class="page-section">
<div class="page-section-title">
<span>Vertical Scroll</span>
<p>纵向滚动</p>
</div>
<div class="page-section-spacing">
<TiScrollView
scroll-y
@scrolltoupper="upper"
@scrolltolower="lower"
@ti-scroll="scroll"
>
<div id="demo1" class="scroll-view-item demo-text-1" />
<div id="demo2" class="scroll-view-item demo-text-2" />
<div id="demo3" class="scroll-view-item demo-text-3" />
</TiScrollView>
</div>
</div>

<div class="page-section">
<div class="page-section-title">
<span>Horizontal Scroll</span>
<p>横向滚动</p>
</div>
<div class="page-section-spacing">
<TiScrollView
scroll-x
extStyle="width: 100%"
@ti-scroll="scroll"
@scrolltoupper="upper"
@scrolltolower="lower"
>
<div id="demo1" class="scroll-view-item-h demo-text-1" />
<div id="demo2" class="scroll-view-item-h demo-text-2" />
<div id="demo3" class="scroll-view-item-h demo-text-3" />
</TiScrollView>
</div>
</div>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { TiScrollView } from '@titian-design/mobile-vue';

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

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

TiScrollView API

属性 Properties

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

事件 Events

名称参数列表说明备注
scrolltoupper(e: CustomEvent) => void滚动到顶部/左边时触发-
scrolltolower(e: CustomEvent) => void滚动到底部/右边时触发-
ti-scroll(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 属性-