index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React, {PureComponent} from "react";
  2. import {Top} from './style';
  3. import {BackTop} from 'antd';
  4. class ToTop extends PureComponent {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. gotoTop: false
  9. };
  10. this.toTopfun = this.toTopfun.bind(this);
  11. }
  12. render() {
  13. return (
  14. <Top>
  15. <div className={this.state.gotoTop ? 'toTop hidden' : 'toTop goTop hidden'}>
  16. <BackTop visibilityHeight={600} onClick={this.toTopfun}/>
  17. <img src={require('../../statics/images/scroll.png')} alt=""/>
  18. </div>
  19. <div className='phone-backtop'>
  20. <BackTop visibilityHeight={600}/>
  21. </div>
  22. </Top>
  23. )
  24. }
  25. componentDidMount() {
  26. window.onscroll = () => {
  27. let t = document.documentElement.scrollTop || document.body.scrollTop;
  28. this.setState({
  29. gotoTop: t > 600
  30. })
  31. }
  32. }
  33. toTopfun() {
  34. this.setState({
  35. gotoTop: false,
  36. });
  37. }
  38. }
  39. export default ToTop