-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollFixedStyle.js
91 lines (66 loc) · 1.63 KB
/
scrollFixedStyle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* This is just a bundle of code taken from a react project which will helps with scrolling
*/
/**
* This goes in App.js
*/
componentDidMount() {
/**
* I want to update the scroll values every time we can repaint the browser.
* RAF is better than scroll because it's patient.
*/
window.requestAnimationFrame(this.captureScrollValues.bind(this));
}
captureScrollValues () {
const node = ReactDOM.findDOMNode(document.body); // eslint-disable-line react/no-find-dom-node
/**
* Push the scrollTop and scrollHeight into the state, so we can use it in other places
*/
this.props.dispatch(updateScrollPosition(node.scrollTop));
this.props.dispatch(updateScrollHeight(node.scrollHeight));
this.props.dispatch(updateScrollStyle({ transform: `translate3d(0, -${ node.scrollTop }px, 0)` }));
/**
* Call the function again (when ready for another paint)
*/
window.requestAnimationFrame(this.captureScrollValues.bind(this));
}
/**
* Action
*/
const constants = {
UPDATE_SCROLL_STYLE: 'UPDATE_SCROLL_STYLE',
};
export function updateScrollStyle(scrollStyle) {
return {
type: constants.UPDATE_SCROLL_STYLE,
scrollStyle
};
}
/**
* Reducer
*/
export default function reducer(state, action) {
switch (action.type) {
case constants.UPDATE_SCROLL_STYLE:
return merge({}, set(state, 'scrollStyle', action.scrollStyle));
}
}
/**
* Component Specific
*/
<div style={ this.props.scrollStyle } >
<h2>News Story Title</h2>
</div>
/**
* CSS
*/
div{
@include transition(0.6s all $easeOutQuint);
}
.main-wrapper{
position: fixed;
width: 100%;
height: 100%;
top: 250px;
left: 0;
}