From 665a9182d34f631c7b43bdff71335d8aa72ddd74 Mon Sep 17 00:00:00 2001 From: jljsj Date: Mon, 12 Dec 2016 17:37:54 +0800 Subject: [PATCH] add element location --- README.md | 5 +++-- examples/scrollScreen.js | 36 +++++++++++++++++++----------------- package.json | 2 +- src/ScrollElement.jsx | 7 +++++-- src/ScrollOverPack.jsx | 1 + 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 00435f2..5cc2254 100644 --- a/README.md +++ b/README.md @@ -120,12 +120,13 @@ ScrollAnim.scrollScreen.unMount(); | id | string | null | need to location the id,parallax the `location` or link the `to`, need to use | | playScale | number / array | `0.5` | percentage of screen to start play, screen center is 0.5, if replay is true : [bottomEnter, topLeave], topLeave >= bottomEnter | | onChange | func | null | change callback({ mode, scrollName }); mode: `enter` or `leave` | +| location | string | null | v0.6.0 above have,location, the parent id; | > Note: if the element is not the above component, you need to location this element; please use the `Element` ### OverPack -OverPack inherit Element; `component` `playScale` `onChange` refer to `Element`; +OverPack inherit Element; `component` `playScale` `onChange` `location` refer to `Element`; | name | type | default | description | |-----------|----------------|---------|----------------| @@ -137,7 +138,7 @@ OverPack inherit Element; `component` `playScale` `onChange` refer to `Element` | name | type | default | description | |-----------|----------------|---------|----------------| | animation | object / array | `null` | animation data | -| location | string | `null` | location, `Element` the id, only scroll name | +| location | string | `null` | location, the parent id | | always | boolean | `true` | - | | component | string | `div` | - | diff --git a/examples/scrollScreen.js b/examples/scrollScreen.js index 93be4a3..adb393b 100644 --- a/examples/scrollScreen.js +++ b/examples/scrollScreen.js @@ -90,23 +90,25 @@ class Demo extends React.Component { - - - 每次进入都启动播放 - - -
-
-
-
-
-
+
+ + + 每次进入都启动播放 + + +
+
+
+
+
+
+
{ class ScrollElement extends React.Component { componentDidMount() { this.dom = ReactDOM.findDOMNode(this); - if (this.props.id) { + if (this.props.location) { + mapped.register(this.props.location, document.getElementById(this.props.location)); + } else if (this.props.id) { mapped.register(this.props.id, this.dom); } const date = Date.now(); @@ -57,7 +59,7 @@ class ScrollElement extends React.Component { render() { const { ...props } = this.props; - ['component', 'playScale'].forEach(key => delete props[key]); + ['component', 'playScale', 'location'].forEach(key => delete props[key]); return React.createElement(this.props.component, { ...props }); } } @@ -67,6 +69,7 @@ ScrollElement.propTypes = { playScale: React.PropTypes.any, id: React.PropTypes.string, onChange: React.PropTypes.func, + location: React.PropTypes.string, }; ScrollElement.defaultProps = { diff --git a/src/ScrollOverPack.jsx b/src/ScrollOverPack.jsx index 2c8a46e..b19af18 100644 --- a/src/ScrollOverPack.jsx +++ b/src/ScrollOverPack.jsx @@ -52,6 +52,7 @@ class ScrollOverPack extends ScrollElement { 'always', 'scrollEvent', 'hideProps', + 'location', ].forEach(key => delete placeholderProps[key]); let childToRender; if (!this.oneEnter && !this.state.show) {