Skip to content

Commit

Permalink
Merge pull request #20 from thierryc/scroll-debounce-v2
Browse files Browse the repository at this point in the history
new debounce srcoll.
  • Loading branch information
thierryc authored Nov 7, 2018
2 parents bccf6b0 + 67345e0 commit c4de310
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion example/src/components/slides/Slide1.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Slide1 = () => (
marginTop: '0.3em',
marginBottom: '0.4em',
}}>Create Fullscreen Scrolling Websites</h2>
<p>Version 0.1.6-alpha</p>
<p>Version 0.1.7-alpha</p>
</div>
</FullpageSection>
);
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": "@ap.cx/react-fullpage",
"version": "0.1.6-alpha",
"version": "0.1.7-alpha",
"description": "Create Beautiful Fullscreen Scrolling Websites",
"author": "thierryc",
"license": "MIT",
Expand Down
20 changes: 11 additions & 9 deletions src/Fullpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,21 @@ class Fullpage extends PureComponent {
window.requestAnimationFrame(() => {
const { resetScroll, translateY, debounceScroll } = this.state;
// resetScroll or prevent scroll for debounceScroll
if (resetScroll || debounceScroll) {
if (resetScroll) {
window.scrollTo(0, translateY * -1);
}

const pageYOffset = window.pageYOffset || 0;
this.setState({
pageYOffset,
resetScroll: false,
});

if (!debounceScroll) {
const pageYOffset = window.pageYOffset || 0;
const newSlide = this.slides.find((slide) => {
const el = slide.el.current;
return pageYOffset < el.offsetTop + (el.offsetHeight * 0.5);
});

this.setState({
pageYOffset,
resetScroll: false,
});

this.goto(newSlide);
}

Expand Down Expand Up @@ -226,7 +225,10 @@ class Fullpage extends PureComponent {
debounceScroll: true,
});

setTimeout(() => this.setState({ debounceScroll: false }), transitionTiming);
setTimeout(() => this.setState({
debounceScroll: false,
resetScroll: true,
}), 700);


const { onShow } = newSlide.props;
Expand Down

0 comments on commit c4de310

Please sign in to comment.