Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class Headroom extends Component {
pinStart: PropTypes.number,
style: PropTypes.object,
calcHeightOnResize: PropTypes.bool,
stickySubheaderStart: PropTypes.number,
};

static defaultProps = {
Expand All @@ -36,6 +37,7 @@ export default class Headroom extends Component {
wrapperStyle: {},
pinStart: 0,
calcHeightOnResize: true,
stickySubheaderStart: 0,
};

constructor (props) {
Expand Down Expand Up @@ -186,21 +188,23 @@ 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',
})
}

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',
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions www/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)