diff --git a/components/anchor/__tests__/__snapshots__/demo.test.js.snap b/components/anchor/__tests__/__snapshots__/demo.test.js.snap index ba9e60649b..4f5e30d5ae 100644 --- a/components/anchor/__tests__/__snapshots__/demo.test.js.snap +++ b/components/anchor/__tests__/__snapshots__/demo.test.js.snap @@ -301,3 +301,83 @@ exports[`renders ./components/anchor/demo/static.md correctly 1`] = ` `; + +exports[`renders ./components/anchor/demo/targetOffset.md correctly 1`] = ` +
+
+ +
+
+`; diff --git a/components/anchor/demo/targetOffset.md b/components/anchor/demo/targetOffset.md new file mode 100644 index 0000000000..3993a1a54e --- /dev/null +++ b/components/anchor/demo/targetOffset.md @@ -0,0 +1,34 @@ +--- +order: 4 +title: + zh-CN: 设置锚点滚动偏移量 + en-US: Set Anchor scroll offset +--- + +## zh-CN + +锚点目标滚动到屏幕正中间。 + +## en-US + +Anchor target scroll to screen center. + +```jsx +import { Anchor } from 'antd'; + +const { Link } = Anchor; + +const targetOffset = window.innerHeight / 2; + +ReactDOM.render( + + + + + + + + , + mountNode, +); +``` diff --git a/components/anchor/index.zh-CN.md b/components/anchor/index.zh-CN.md index e9d0bef06e..7d3f188d7c 100644 --- a/components/anchor/index.zh-CN.md +++ b/components/anchor/index.zh-CN.md @@ -26,7 +26,7 @@ title: Anchor | showInkInFixed | 固定模式是否显示小圆点 | boolean | false | | | onClick | `click` 事件的 handler | Function(e: Event, link: Object) | - | 3.9.0 | | getCurrentAnchor | 自定义高亮的锚点 | () => string | - | 3.21.0 | -| targetOffset | 滚动到目标的偏移量 | number | `offsetTop` | | 0 | 3.21.0 | +| targetOffset | 锚点滚动偏移量,默认与 offsetTop 相同,[例子](#components-anchor-demo-targetOffset) | number | `offsetTop` | 3.21.0 | ### Link Props