logo

S2

  • Manual
  • API
  • Examples
  • Playground
  • ChangeLog
  • Productsantv logo arrow
  • 2.x
  • Introduction
  • Quick Start
  • Basic Tutorial
    • Base Concept
    • Sheet Type
      • Pivot Mode
        Updated
      • Table Mode
    • Conditions
      Updated
    • Totals
    • Sort
      • Custom Sort
        Updated
      • Group Sort
        Updated
    • Theme
      Updated
    • Tooltip
      Updated
    • Internationalization
    • 数据格式化
      New
    • Multi Line
      New
    • Pagination
      New
  • Advanced Tutorial
    • Advanced Tutorial
      • Link
      • Render Chart In Cell
      • Draw Chart With @antv/g2
    • Custom
      • Customize Hook
        Updated
      • Customize Tree
        New
      • Customize Icon
      • Customize Cell Alignment
      • Customize Cell Size
        Updated
      • Customize Order
      • Custom Collapse/Expand Nodes
    • Interaction
      • Basic Interaction
      • Custom Interaction
      • Hide Columns
      • Cell Resize
      • Merge Cell
      • Scroll
      • Copy
        New
      • Highlight and select cell
        New
    • Analyze Component
      • Introduction
        New
      • Advanced Sort
        Updated
      • Switcher
      • Export
        Updated
      • Pagination
      • Drill Down
    • Sheet Component
      • Editable Mode
      • Strategy Sheet
        Updated
    • HD Adapter
    • Get Instance
    • Get Cell Data
      Updated
    • Table adaptive
    • AntV/G Plugins
      New
    • Pivot Chart
      Experimental
    • Vue 3.0
  • Extended Reading
    • Data Process
      • Pivot
      • Table
    • Layout
      • Pivot
      • Table
    • Performance
      Updated
  • Contribution
  • FAQ
  • S2 2.0 Migration Guide

Scroll

Previous
Merge Cell
Next
Copy

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

virtual scroll

S2 is based on Canvas rendering, and also realizes virtual scrolling, that is, only cells in the visible area are rendered, which is enabled by default. see more

200 ms delay effect

preview

custom scroll speed

The scrollSpeedRatio can be configured to control the scroll rate, which is divided into two directions:水平and垂直. The range is 0-1 , and the default is 1 . View specific examples

const s2Options = {
interaction: {
scrollSpeedRatio: {
vertical: 0.3, // 垂直
horizontal: 1, // 水平
},
},
};

mouse wheel scrolling horizontally

Swipe the scroll wheel to scroll vertically, if you hold Shift at the same time, you can scroll horizontally

Modify scroll to bounds behavior

When there are scroll bars in both itself and the parent container, the browser's default scrolling behavior is: non-border does not trigger the parent container to scroll, and when the border is reached, the parent container is triggered to scroll, and you can also configure overscroll-behavior to change the default behavior.

S2 is a virtual scroll, but it also simulates the scrolling behavior of the browser, and the overscrollBehavior can be configured to control the non-boundary scrolling behavior. view example

const s2Options = {
interaction: {
overscrollBehavior: 'auto' // 'auto' | 'none' | 'contain';
overscrollBehavior: null // 设为 null 则不做任何处理
},
};
  • auto : Same as browser scrolling behavior
preview
  • contain : After scrolling to the border, the parent container will not be triggered to scroll
preview
  • none : After scrolling to the boundary, the parent container will not be triggered to scroll, and the default scrolling behavior of the browser will be disabled, such as triggering page pull-down to refresh , and triggering return when the Mac touchpad scrolls horizontally . See more
previewpreview

Note : When overscrollBehavior is configured, the corresponding overscroll-behavior attribute will be additionally added to the body to achieve the purpose of disabling the browser's default scrolling behavior

preview

Listen for scrolling events

For the透视表, the scrollable area is行头单元格and the数值单元格respectively; for the明细表, the scrollable area is only the数值单元格, which can be monitored separately or collectively

preview

S2 provides two kinds of scrolling events:

  • S2Event.GLOBAL_SCROLL : Cell scrolling, triggers when the value/row header cell scrolls
  • S2Event.ROW_CELL_SCROLL : row header cell scrolling

At the same time: For the s2-react and s2-vue versions, event mapping is also provided, please refer to the API documentation for details

It should be noted that the row header cell will only display the scroll bar when the row header is fixed , and there will only be a horizontal scroll bar , so the scrollY will always be 0

import { S2Event } from '@antv/s2';
s2.on(S2Event.GLOBAL_SCROLL, (position) => {
console.log('表格滚动', position) // { scrollX: 0, scrollY: 100 }
})
s2.on(S2Event.ROW_CELL_SCROLL, (position) => {
console.log('行头单元格滚动', position) // { scrollX: 0, scrollY: 100 }
})

Manually trigger table scrolling

Consider the following examples:

  • Scroll to the specified cell
  • cycle scrolling