From 3c2afab6d811faf7d597b0dbae8faae128d3c0cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Thu, 30 Jan 2020 10:36:47 +0800 Subject: [PATCH] feat(Sticky): offset-top can be string --- src/sticky/README.md | 4 ++-- src/sticky/README.zh-CN.md | 4 ++-- src/sticky/index.js | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sticky/README.md b/src/sticky/README.md index 0cba4c66d..2820ddfca 100644 --- a/src/sticky/README.md +++ b/src/sticky/README.md @@ -56,9 +56,9 @@ export default { | Attribute | Description | Type | Default | |------|------|------|------| -| offset-top | Offset top | *number* | `0` | +| offset-top | Offset top | *number \| string* | `0` | | z-index | z-index when sticky | *number \| string* | `99` | -| container | Container DOM | *HTMLElement* | - | +| container | Container DOM | *Element* | - | ### Events diff --git a/src/sticky/README.zh-CN.md b/src/sticky/README.zh-CN.md index 9afb7e5a7..4f61d913a 100644 --- a/src/sticky/README.zh-CN.md +++ b/src/sticky/README.zh-CN.md @@ -66,9 +66,9 @@ export default { | 参数 | 说明 | 类型 | 默认值 | |------|------|------|------| -| offset-top | 吸顶时与顶部的距离,单位`px` | *number* | `0` | +| offset-top | 吸顶时与顶部的距离,单位`px` | *number \| string* | `0` | | z-index | 吸顶时的 z-index | *number \| string* | `99` | -| container | 容器对应的 HTML 节点 | *HTMLElement* | - | +| container | 容器对应的 HTML 节点 | *Element* | - | ### Events diff --git a/src/sticky/index.js b/src/sticky/index.js index f702fc49f..f1a496751 100644 --- a/src/sticky/index.js +++ b/src/sticky/index.js @@ -20,7 +20,7 @@ export default createComponent({ zIndex: [Number, String], container: null, offsetTop: { - type: Number, + type: [Number, String], default: 0, }, }, @@ -61,7 +61,8 @@ export default createComponent({ onScroll() { this.height = this.$el.offsetHeight; - const { container, offsetTop } = this; + const { container } = this; + const offsetTop = +this.offsetTop; const scrollTop = getScrollTop(window); const topToPageTop = getElementTop(this.$el);