Skip to content

Commit eaa8c54

Browse files
Added a scroll to top component (#188)
* Added a scroll to top component * Fixed mobile view bug
1 parent e72aa55 commit eaa8c54

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.scroll-to-top {
2+
position: fixed;
3+
bottom: 0.5rem;
4+
right: 0.5rem;
5+
animation: fadeIn 700ms ease-in-out 1s both;
6+
cursor: pointer;
7+
z-index:999;
8+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React, { Component } from "react";
2+
import './ScrollToTopBtn.css';
3+
4+
class ScrollToTopBtn extends Component {
5+
constructor(props) {
6+
super(props);
7+
this.state = {
8+
is_visible: false
9+
};
10+
}
11+
12+
componentDidMount() {
13+
var scrollComponent = this;
14+
document.addEventListener("scroll", function (e) {
15+
scrollComponent.toggleVisibility();
16+
});
17+
}
18+
19+
toggleVisibility() {
20+
if (window.pageYOffset > 50) {
21+
this.setState({
22+
is_visible: true
23+
});
24+
} else {
25+
this.setState({
26+
is_visible: false
27+
});
28+
}
29+
}
30+
31+
scrollToTop() {
32+
window.scrollTo({
33+
top: 0,
34+
behavior: "smooth"
35+
});
36+
}
37+
38+
render() {
39+
const { is_visible } = this.state;
40+
return (
41+
<div className="scroll-to-top">
42+
{is_visible && (
43+
<div onClick={() => this.scrollToTop()}>
44+
<span class="fa-stack fa-lg">
45+
<i class="fa fa-circle fa-stack-2x"></i>
46+
<i class="fa fa-arrow-up fa-stack-1x fa-inverse" aria-hidden="true"></i>
47+
</span>
48+
</div>
49+
)}
50+
</div>
51+
);
52+
}
53+
}
54+
55+
export default ScrollToTopBtn;

β€Žsrc/pages/About/About.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Markdown from 'react-markdown';
55
import './About.css'
66
import marked from "marked";
77
import codeuino from './codeuino-banner.jpg'
8+
import ScrollToTopBtn from '../../components/ScrollToTopBtn/ScrollToTopBtn.js';
89
class Blog extends Component {
910
constructor(props){
1011
super(props);
@@ -57,6 +58,7 @@ class Blog extends Component {
5758
</div>
5859
</div>
5960
</div>
61+
<ScrollToTopBtn />
6062
</div>
6163
);
6264
}

β€Žsrc/pages/Home/NewHome.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import './NewHome.css';
3-
3+
import ScrollToTopBtn from '../../components/ScrollToTopBtn/ScrollToTopBtn.js';
44
import Projects from './Components/Projects'
55
import LandingPageComponent from './Components/LandingPageComponent'
66
import Activities from './Components/Activities'
@@ -15,6 +15,7 @@ const NewHome = () => {
1515
<Projects/>
1616
<Activities/>
1717
<Partners/>
18+
<ScrollToTopBtn />
1819
</div>
1920
</div>
2021
</div>

β€Žsrc/pages/Team/Team.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import PropTypes from 'prop-types';
66
import './Team.css';
77
import BoardMembersWrapper from './BoardMembers'
88
import CoreContributorsWrapper from './CoreContributors'
9+
import ScrollToTopBtn from '../../components/ScrollToTopBtn/ScrollToTopBtn.js';
910
import axios from 'axios';
1011
import $ from 'jquery';
1112
class Team extends Component {
@@ -63,6 +64,7 @@ class Team extends Component {
6364
</div>
6465
</div>
6566
</div>
67+
<ScrollToTopBtn />
6668
</>
6769
);
6870
}

0 commit comments

Comments
 (0)