2018-08-28 18:56:25 +08:00
|
|
|
---
|
|
|
|
order: 12
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义页签头
|
|
|
|
en-US: Customized bar of tab
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
使用 react-sticky 组件实现吸顶效果。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2019-08-07 17:26:39 +08:00
|
|
|
Use react-sticky.
|
2018-08-28 18:56:25 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2018-08-28 18:56:25 +08:00
|
|
|
import { Tabs } from 'antd';
|
|
|
|
import { StickyContainer, Sticky } from 'react-sticky';
|
|
|
|
|
2019-05-27 21:32:45 +08:00
|
|
|
const { TabPane } = Tabs;
|
2018-08-28 18:56:25 +08:00
|
|
|
|
|
|
|
const renderTabBar = (props, DefaultTabBar) => (
|
|
|
|
<Sticky bottomOffset={80}>
|
|
|
|
{({ style }) => (
|
2019-12-24 20:58:42 +08:00
|
|
|
<DefaultTabBar {...props} className="site-custom-tab-bar" style={{ ...style }} />
|
2018-08-28 18:56:25 +08:00
|
|
|
)}
|
|
|
|
</Sticky>
|
|
|
|
);
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<StickyContainer>
|
|
|
|
<Tabs defaultActiveKey="1" renderTabBar={renderTabBar}>
|
2019-05-07 14:57:32 +08:00
|
|
|
<TabPane tab="Tab 1" key="1" style={{ height: 200 }}>
|
|
|
|
Content of Tab Pane 1
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Tab 2" key="2">
|
|
|
|
Content of Tab Pane 2
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Tab 3" key="3">
|
|
|
|
Content of Tab Pane 3
|
|
|
|
</TabPane>
|
2018-08-28 18:56:25 +08:00
|
|
|
</Tabs>
|
|
|
|
</StickyContainer>,
|
2019-05-07 14:57:32 +08:00
|
|
|
mountNode,
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|
2019-12-24 20:58:42 +08:00
|
|
|
|
|
|
|
```css
|
|
|
|
.site-custom-tab-bar {
|
|
|
|
z-index: 1;
|
|
|
|
background: #fff;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
<style>
|
|
|
|
[data-theme="dark"] .site-custom-tab-bar {
|
|
|
|
background: #141414;
|
|
|
|
}
|
|
|
|
</style>
|