Compare commits
3 commits
main
...
scroll-to-
| Author | SHA1 | Date | |
|---|---|---|---|
| 859c02195c | |||
| 38b2d91f18 | |||
| b9c749d4e4 |
6 changed files with 80 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import { isEqual } from 'lodash';
|
|||
|
||||
import { fetchCategories } from './actions/categories';
|
||||
|
||||
import ScrollTop from './components/ScrollTop.js';
|
||||
import Sidebar from './components/sidebar/Sidebar.js';
|
||||
import PostList from './components/postlist/PostList.js';
|
||||
import PostModal from './components/PostModal.js';
|
||||
|
|
@ -41,6 +42,8 @@ class App extends React.Component {
|
|||
/>
|
||||
)}
|
||||
|
||||
<ScrollTop />
|
||||
|
||||
{this.props.error && (
|
||||
<Messages messages={[{ type: 'error', text: this.props.error.message }]} />
|
||||
)}
|
||||
|
|
|
|||
40
src/newsreader/js/pages/homepage/components/ScrollTop.js
Normal file
40
src/newsreader/js/pages/homepage/components/ScrollTop.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import React from 'react';
|
||||
|
||||
export default class ScrollTop extends React.Component {
|
||||
scrollListener = ::this.scrollListener;
|
||||
|
||||
state = { showTop: false, showBottom: false };
|
||||
|
||||
componentDidMount() {
|
||||
window.addEventListener('scroll', this.scrollListener);
|
||||
}
|
||||
|
||||
scrollListener() {
|
||||
const showBottom = window.innerHeight + window.scrollY < document.body.offsetHeight;
|
||||
|
||||
this.setState({
|
||||
showTop: window.pageYOffset > 0 ? true : false,
|
||||
showBottom: showBottom,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="scroll-to-top">
|
||||
{this.state.showTop && (
|
||||
<i
|
||||
className="scroll-to-top__icon scroll-to-top__icon--top"
|
||||
onClick={() => window.scrollTo(0, 0)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{this.state.showBottom && (
|
||||
<i
|
||||
className="scroll-to-top__icon scroll-to-top__icon--bottom"
|
||||
onClick={() => window.scrollTo(0, document.body.scrollHeight)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -26,3 +26,4 @@
|
|||
@import './post-message/index';
|
||||
@import './posts/index';
|
||||
@import './posts-info/index';
|
||||
@import './scroll-to-top/index';
|
||||
|
|
|
|||
|
|
@ -5,4 +5,6 @@
|
|||
padding: 0;
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
z-index: 1000;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
.scroll-to-top {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
|
||||
position: fixed;
|
||||
right: 15%;
|
||||
bottom: 0;
|
||||
|
||||
margin: 0 0 20px 0;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&__icon {
|
||||
font-style: initial;
|
||||
padding: 10px;
|
||||
|
||||
background-color: var(--lightest-accent-color);
|
||||
|
||||
&--top:before {
|
||||
@include font-awesome;
|
||||
|
||||
content: "\f062";
|
||||
}
|
||||
|
||||
&--bottom:before {
|
||||
@include font-awesome;
|
||||
|
||||
content: "\f063";
|
||||
}
|
||||
}
|
||||
}
|
||||
1
src/newsreader/scss/components/scroll-to-top/index.scss
Normal file
1
src/newsreader/scss/components/scroll-to-top/index.scss
Normal file
|
|
@ -0,0 +1 @@
|
|||
@import './scroll-to-top';
|
||||
Loading…
Add table
Add a link
Reference in a new issue