Skip to content

Commit

Permalink
add element location
Browse files Browse the repository at this point in the history
  • Loading branch information
jljsj33 committed Dec 12, 2016
1 parent 61b9273 commit 665a918
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|-----------|----------------|---------|----------------|
Expand All @@ -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` | - |

Expand Down
36 changes: 19 additions & 17 deletions examples/scrollScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,25 @@ class Demo extends React.Component {
</div>
</QueueAnim>
</Element>
<ScrollOverPack
id="page1"
className="page1"
playScale={1}
replay
hideProps={{ 0: { reverse: true } }}
>
<TweenOne className="tween-one" key="0" animation={{ opacity: 1 }}>
每次进入都启动播放
</TweenOne>
<QueueAnim key="1" style={{ height: 100 }}>
<div key="0" className="demo"></div>
<div key="1" className="demo"></div>
<div key="2" className="demo"></div>
<div key="3" className="demo"></div>
</QueueAnim>
</ScrollOverPack>
<div id="page1">
<ScrollOverPack
className="page1"
playScale={1}
replay
hideProps={{ 0: { reverse: true } }}
location="page1"
>
<TweenOne className="tween-one" key="0" animation={{ opacity: 1 }}>
每次进入都启动播放
</TweenOne>
<QueueAnim key="1" style={{ height: 100 }}>
<div key="0" className="demo"></div>
<div key="1" className="demo"></div>
<div key="2" className="demo"></div>
<div key="3" className="demo"></div>
</QueueAnim>
</ScrollOverPack>
</div>

<ScrollOverPack
className="pack-page page2"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-scroll-anim",
"version": "0.5.3",
"version": "0.6.0",
"description": "scroll-anim anim component for react",
"keywords": [
"react",
Expand Down
7 changes: 5 additions & 2 deletions src/ScrollElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const noop = () => {
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();
Expand Down Expand Up @@ -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 });
}
}
Expand All @@ -67,6 +69,7 @@ ScrollElement.propTypes = {
playScale: React.PropTypes.any,
id: React.PropTypes.string,
onChange: React.PropTypes.func,
location: React.PropTypes.string,
};

ScrollElement.defaultProps = {
Expand Down
1 change: 1 addition & 0 deletions src/ScrollOverPack.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 665a918

Please sign in to comment.