diff --git a/components/affix/demo/basic.md b/components/affix/demo/basic.md new file mode 100644 index 000000000..83fdba97c --- /dev/null +++ b/components/affix/demo/basic.md @@ -0,0 +1,23 @@ + +#### 基本 +最简单的用法。 + + + +#### basic +The simplest usage. + + +```html + +``` diff --git a/components/affix/demo/index.vue b/components/affix/demo/index.vue new file mode 100644 index 000000000..fede96675 --- /dev/null +++ b/components/affix/demo/index.vue @@ -0,0 +1,37 @@ + diff --git a/components/affix/demo/on-change.md b/components/affix/demo/on-change.md new file mode 100644 index 000000000..f79fb1feb --- /dev/null +++ b/components/affix/demo/on-change.md @@ -0,0 +1,26 @@ + +#### 固定状态改变的回调 +可以获得是否固定的状态。 + + + +#### Callback +Callback with affixed state. + + +```html + + +``` diff --git a/components/affix/demo/target.md b/components/affix/demo/target.md new file mode 100644 index 000000000..0c071e081 --- /dev/null +++ b/components/affix/demo/target.md @@ -0,0 +1,34 @@ + +#### 滚动容器 +用 `target` 设置 `Affix` 需要监听其滚动事件的元素,默认为 `window`。 + + + +#### Container to scroll. +Set a `target` for 'Affix', which is listen to scroll event of target element (default is `window`). + + +```html + + +``` diff --git a/components/affix/index.en-US.md b/components/affix/index.en-US.md new file mode 100644 index 000000000..b58ff8bfe --- /dev/null +++ b/components/affix/index.en-US.md @@ -0,0 +1,21 @@ + +## API + +| Property | Description | Type | Default | +| -------- | ----------- | ---- | ------- | +| offsetBottom | Pixels to offset from bottom when calculating position of scroll | number | - | +| offsetTop | Pixels to offset from top when calculating position of scroll | number | 0 | +| target | specifies the scrollable area dom node | () => HTMLElement | () => window | + +### events +| Events Name | Description | Arguments | +| --- | --- | --- | +| onChange | Callback for when affix state is changed | Function(affixed) | + +**Note:** Children of `Affix` can not be `position: absolute`, but you can set `Affix` as `position: absolute`: + +````html + + ... + +```` diff --git a/components/affix/index.vue b/components/affix/index.vue index a02185f4a..78fd1432b 100644 --- a/components/affix/index.vue +++ b/components/affix/index.vue @@ -5,7 +5,8 @@ import classNames from 'classnames' import shallowequal from 'shallowequal' import omit from 'omit.js' import getScroll from '../_util/getScroll' -import { throttleByAnimationFrameDecorator } from '../_util/throttleByAnimationFrame' +import BaseMixin from '../_util/BaseMixin' +import throttleByAnimationFrame from '../_util/throttleByAnimationFrame' function getTargetRect (target) { return target !== window @@ -55,14 +56,10 @@ const AffixProps = { prefixCls: PropTypes.string, } -// export interface AffixState { -// affixStyle: React.CSSProperties | undefined; -// placeholderStyle: React.CSSProperties | undefined; -// } - export default { name: 'Affix', props: AffixProps, + mixins: [BaseMixin], data () { this.events = [ 'resize', @@ -79,6 +76,9 @@ export default { placeholderStyle: undefined, } }, + beforeMount () { + this.updatePosition = throttleByAnimationFrame(this.updatePosition) + }, mounted () { const target = this.target || getDefaultTarget // Wait for parent component ref has its value @@ -96,7 +96,6 @@ export default { }) }, }, - beforeDestroy () { this.clearEventListeners() clearTimeout(this.timeout) @@ -130,7 +129,6 @@ export default { this.setState({ placeholderStyle: placeholderStyle }) }, - // @throttleByAnimationFrameDecorator() updatePosition (e) { let { offsetTop } = this const { offsetBottom, offset, target = getDefaultTarget } = this @@ -244,4 +242,4 @@ export default { }, } - \ No newline at end of file + diff --git a/components/affix/index.zh-CN.md b/components/affix/index.zh-CN.md new file mode 100644 index 000000000..b3160e1b6 --- /dev/null +++ b/components/affix/index.zh-CN.md @@ -0,0 +1,23 @@ + +## API + +| 成员 | 说明 | 类型 | 默认值 | +| --- | --- | --- | --- | +| offsetBottom | 距离窗口底部达到指定偏移量后触发 | number | | +| offsetTop | 距离窗口顶部达到指定偏移量后触发 | number | | +| target | 设置 `Affix` 需要监听其滚动事件的元素,值为一个返回对应 DOM 元素的函数 | () => HTMLElement | () => window | + + +### 事件 +| 事件名称 | 说明 | 回调参数 | +| --- | --- | --- | +| change | 固定状态改变时触发的回调函数 | Function(affixed) | + + +**注意:**`Affix` 内的元素不要使用绝对定位,如需要绝对定位的效果,可以直接设置 `Affix` 为绝对定位: + +````html + + ... + +```` diff --git a/components/button/demo/basic.md b/components/button/demo/basic.md index de0910473..55943099f 100644 --- a/components/button/demo/basic.md +++ b/components/button/demo/basic.md @@ -11,7 +11,7 @@ There are `primary` button, `default` button, `dashed` button and `danger` butto ```html