ant-design/components/affix/demo/target.md
二货机器人 55e0d13234
chore: Add demo tsx check (#28389)
* chore: Add demo tsx check

* chore: Prettier

* chore: Fix lint

* fix: Upload ts definition

* chore: Demo onlt

* docs: Fix demo

* chore: Add CI action

* chore: Use real name

* chore: fix ts define

* chore: fix more ts

* chore: fix more ts

* chore: More ts

* chore: More ts

* chore: More ts

* chore: More ts

* chore: More ts

* chore: More ts

* chore: More ts

* chore: Update all rest TS demo

* fix test case
2020-12-17 15:09:18 +08:00

1.1 KiB

order title
2
zh-CN en-US
滚动容器 Container to scroll.

zh-CN

target 设置 Affix 需要监听其滚动事件的元素,默认为 window

en-US

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

import React, { useState } from 'react';
import { Affix, Button } from 'antd';

const Demo: React.FC = () => {
  const [container, setContainer] = useState<HTMLDivElement | null>(null);
  return (
    <div className="scrollable-container" ref={setContainer}>
      <div className="background">
        <Affix target={() => container}>
          <Button type="primary">Fixed at the top of container</Button>
        </Affix>
      </div>
    </div>
  );
};

ReactDOM.render(<Demo />, mountNode);