Skip to content

Commit

Permalink
Remove unnecessary scroll behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rthor committed Oct 25, 2017
1 parent 657a12e commit 11ba352
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
36 changes: 1 addition & 35 deletions src/routes/prof-nidurstodur/KosningaProf.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,12 @@ class Kosningaprof extends PureComponent {

this.positions = {};

this.onScroll = this.onScroll.bind(this);
this.onLayout = this.onLayout.bind(this);
this.onReset = this.onReset.bind(this);
this.onSend = this.onSend.bind(this);
}
componentDidMount() {
window.addEventListener('resize', this.onLayout);
window.addEventListener('layout', this.onLayout);
window.addEventListener('scroll', this.onScroll);

this.onLayout();
this.onScroll();
this.loadAnswers();
}
componentWillUnmount() {
window.removeEventListener('resize', this.onLayout);
window.removeEventListener('layout', this.onLayout);
window.removeEventListener('scroll', this.onScroll);
}
onReset() {
// eslint-disable-next-line
if (window.confirm('Ertu viss um að þú byrja upp á nýtt?')) {
Expand All @@ -97,23 +84,6 @@ class Kosningaprof extends PureComponent {
};
});
};
onLayout() {
this.questionsEl.childNodes.forEach(question => {
const { top } = question.getBoundingClientRect();
this.positions[question.id] = top;
});
this.viewHeight = window.innerHeight;
}
onScroll() {
const bottom = window.pageYOffset + 0.75 * this.viewHeight;
const visible = {};

Object.keys(this.positions).forEach(id => {
visible[id] = this.positions[id] < bottom;
});

this.setState({ visible });
}
async onSend() {
const { answers } = this.state;
const answerValues = Object.keys(answers)
Expand Down Expand Up @@ -156,11 +126,7 @@ class Kosningaprof extends PureComponent {
}}
>
{questions.map(({ question, id }) => (
<div
key={id}
id={id}
className={cx(s.question, !visible[id] && s.hidden)}
>
<div key={id} id={id} className={cx(s.question)}>
<h3>{question}</h3>
<Slider
dots
Expand Down
4 changes: 2 additions & 2 deletions src/routes/prof-nidurstodur/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
}

.dot {
background-color: #777;
box-shadow: 0 0 4px 0 #777;
background-color: #aaa;
box-shadow: 0 0 4px 0 #aaa;
border-radius: 50%;
display: inline-block;
box-sizing: content-box;
Expand Down

0 comments on commit 11ba352

Please sign in to comment.