diff --git a/src/index.js b/src/index.js index 1effac62..237e9bd5 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,7 @@ export default class Headroom extends Component { pinStart: PropTypes.number, style: PropTypes.object, calcHeightOnResize: PropTypes.bool, + stickySubheaderStart: PropTypes.number, }; static defaultProps = { @@ -36,6 +37,7 @@ export default class Headroom extends Component { wrapperStyle: {}, pinStart: 0, calcHeightOnResize: true, + stickySubheaderStart: 0, }; constructor (props) { @@ -186,10 +188,11 @@ export default class Headroom extends Component { } unpin = () => { - this.props.onUnpin() + const { onUnpin, stickySubheaderStart } = this.props + onUnpin() this.setState({ - translateY: '-100%', + translateY: stickySubheaderStart ? `-${stickySubheaderStart}px` : '-100%', className: 'headroom headroom--unpinned', animation: true, state: 'unpinned', @@ -197,10 +200,11 @@ export default class Headroom extends Component { } unpinSnap = () => { - this.props.onUnpin() + const { onUnpin, stickySubheaderStart } = this.props + onUnpin() this.setState({ - translateY: '-100%', + translateY: stickySubheaderStart ? `-${stickySubheaderStart}px` : '-100%', className: 'headroom headroom--unpinned headroom-disable-animation', animation: false, state: 'unpinned', @@ -268,6 +272,7 @@ export default class Headroom extends Component { delete divProps.downTolerance delete divProps.pinStart delete divProps.calcHeightOnResize + delete divProps.stickySubheaderStart const { style, wrapperStyle, ...rest } = divProps diff --git a/www/pages/index.md b/www/pages/index.md index edc4808d..5df7730b 100644 --- a/www/pages/index.md +++ b/www/pages/index.md @@ -76,3 +76,4 @@ Another option is to use CSS. The component has a `headroom` class as well as a * `wrapperStyle` — pass styles for the wrapper div (this maintains the components vertical space at the top of the page). * `parent` — provide a custom 'parent' element for scroll events. `parent` should be a function which resolves to the desired element. * `pinStart` — height in px where the header should start and stop pinning. Useful when you have another element above Headroom component. +* `stickySubheaderStart` - height in px of the main header that should not be sticky (only provide this value if you want a sticky subheader)