logoNamu Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
1.0.0
  • Components Overview
  • General
    • Button
    • FloatButtonNew
    • Icon
    • Typography
  • Layout
    • Divider
    • Grid
    • Layout
    • Space
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPickerNew
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
    • Popover
    • QRCodeNew
    • Segmented
    • Statistic
    • Table
    • Tabs
    • Tag
    • Timeline
    • Tooltip
    • TourNew
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • AppNew
    • ConfigProvider
When To Use
Examples
Basic
Callback
Container to scroll.
API
FAQ
When binding container with target in Affix, elements sometimes move out of the container.
When Affix is ​​used in a horizontal scroll container, the position of the element left is incorrect.

Affix

  • WatermarkApp

    Resources

    Namu Design Charts
    Namu Design Pro
    Namu Design Pro Components
    Namu Design Mobile
    Namu Design Mini
    Namu Design Landing-Landing Templates
    Scaffolds-Scaffold Market
    Umi-React Application Framework
    dumi-Component doc generator
    qiankun-Micro-Frontends Framework
    ahooks-React Hooks Library
    Ant Motion-Motion Solution
    China Mirror 🇨🇳

    Community

    Awesome Namu Design
    Medium
    Twitter
    yuqueNamu Design in YuQue
    Namu Design in Zhihu
    Experience Cloud Blog
    seeconfSEE Conf-Experience Tech Conference

    Help

    GitHub
    Change Log
    FAQ
    Bug Report
    Issues
    Discussions
    StackOverflow
    SegmentFault

    Ant XTechMore Products

    yuqueYuQue-Document Collaboration Platform
    AntVAntV-Data Visualization
    EggEgg-Enterprise Node.js Framework
    kitchenKitchen-Sketch Toolkit
    xtechAnt Financial Experience Tech
    Theme Editor
    Made with ❤ by
    Ant Group and Namu Design Community

    Wrap Affix around another component to make it stick the viewport.

    When To Use

    On longer web pages, it's helpful to stick component into the viewport. This is common for menus and actions.

    Please note that Affix should not cover other content on the page, especially when the size of the viewport is small.

    Examples

    Basic

    The simplest usage.

    expand codeexpand code
    Container to scroll.

    Set a target for 'Affix', which is listen to scroll event of target element (default is window).

    expand codeexpand code
    Callback

    Callback with affixed state.

    expand codeexpand code

    API

    Common props ref:Common props

    PropertyDescriptionTypeDefault
    offsetBottomOffset from the bottom of the viewport (in pixels)number-
    offsetTopOffset from the top of the viewport (in pixels)number0
    targetSpecifies the scrollable area DOM node() => HTMLElement() => window
    onChangeCallback for when Affix state is changed(affixed?: boolean) => void-

    Note: Children of Affix must not have the property position: absolute, but you can set position: absolute on Affix itself:

    <Affix style={{ position: 'absolute', top: y, left: x }}>...</Affix>

    FAQ

    When binding container with target in Affix, elements sometimes move out of the container.

    We only listen to container scroll events for performance consideration. You can add custom listeners if you still want to: https://codesandbox.io/s/stupefied-maxwell-ophqnm?file=/index.js

    Related issues:#3938 #5642 #16120

    When Affix is ​​used in a horizontal scroll container, the position of the element left is incorrect.

    Affix is ​​generally only applicable to areas with one-way scrolling, and only supports usage in vertical scrolling containers. If you want to use it in a horizontal container, you can consider implementing with the native position: sticky property.

    Related issues:#29108