From 7952215a48d3749f98af15385d3f456ad76be82c Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 26 Jul 2016 18:35:38 +0800 Subject: [PATCH] fix hash scroll --- CHANGELOG.md | 2 +- docs/pattern/navigation.md | 2 +- site/theme/template/Content/MainContent.jsx | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e93b0f8c6..79a34be32b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -230,7 +230,7 @@ timeline: true - **兼容 React@15.x**。 - **全新单页站点**,使用 React 和 antd 进行了彻底重构,加载更快,访问更流畅。 - **样式支持按需加载**。可参考 [antd-init](https://github.com/ant-design/antd-init) 的模版代码, 需要配合 [babel-plugin-antd](https://github.com/ant-design/babel-plugin-antd#usage) 插件和 `style` 配置进行使用。[#900](https://github.com/ant-design/ant-design/issues/900) -- **提供独立的构建文件**。[文档](/docs/react/install?scrollTo=浏览器引入) +- **提供独立的构建文件**。[文档](/docs/react/install#浏览器引入) - 新增卡片组件 [Card](/components/card)。 - 新增评分组件 [Rate](/components/rate)。 - 新增 [LocaleProvider](/components/locale-provider) 组件,提供组件文案的国际化支持,并新增了英语和俄语的语言配置。[#1411](https://github.com/ant-design/ant-design/issues/1411) diff --git a/docs/pattern/navigation.md b/docs/pattern/navigation.md index acd52a3b67..2c635d882f 100644 --- a/docs/pattern/navigation.md +++ b/docs/pattern/navigation.md @@ -39,7 +39,7 @@ english: Navigation 我们将常见的导航模式分为:侧栏导航和顶部导航,两者各有优缺点,设计者可以根据各自的业务需求进行选择。 -前端实现代码可以参考 [常用布局](/docs/spec/layout?scrollTo=components-spec-demo-top)。 +前端实现代码可以参考 [常用布局](/docs/spec/layout#docs-spec-layout-demo-top)。 ## 侧栏导航 diff --git a/site/theme/template/Content/MainContent.jsx b/site/theme/template/Content/MainContent.jsx index 625e238680..509da4282f 100644 --- a/site/theme/template/Content/MainContent.jsx +++ b/site/theme/template/Content/MainContent.jsx @@ -14,15 +14,19 @@ export default class MainContent extends React.Component { componentDidMount() { this.componentDidUpdate(); - this.timer = setTimeout(() => { - document.getElementById(decodeURI(location.hash.replace('#', ''))).scrollIntoView(); - }, 10); } componentDidUpdate() { if (!location.hash) { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; + } else { + if (this.timer) { + clearTimeout(this.timer); + } + this.timer = setTimeout(() => { + document.getElementById(decodeURI(location.hash.replace('#', ''))).scrollIntoView(); + }, 10); } }