Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import React from "react"
  2. import ReactDOM from "react-router-dom"
  3.  
  4. class OnScrollComponent extends React.Component{
  5. constructor(props){
  6. super(props)
  7. this.state = {
  8. open: false,
  9. firstTransitionPosition: 0,
  10. scrollAppearanceAjustment: this.props.scrollAppearanceAjustment || 250
  11. }
  12. this.handleScroll = this.checkForScroll.bind(this)
  13. this.hasBeenSet = false
  14. }
  15.  
  16. checkForScroll() {
  17. if (window.scrollY >= this.state.firstTransitionPosition && this.hasBeenSet == false) {
  18. console.log("this event is triggering")
  19. console.log(this.state.firstTransitionPosition)
  20. this.setState({open: true})
  21. this.hasBeenSet = true
  22. }
  23. }
  24.  
  25. mouseEnter() {
  26. console.log("hello, the mouse is here")
  27. }
  28.  
  29. mouseExit() {
  30. console.log("bye bye, the mouse is gone")
  31. }
  32.  
  33. componentDidMount(){
  34. var transitionComp = this.refs.moveMe
  35. var topOfElement = transitionComp.getBoundingClientRect().top
  36. var heightOfElement = transitionComp.getBoundingClientRect().height
  37. this.setState({firstTransitionPosition: topOfElement - heightOfElement - this.state.scrollAppearanceAjustment}, () => {
  38. this.checkForScroll()
  39. });
  40. window.addEventListener('scroll', this.handleScroll);
  41.  
  42. }
  43.  
  44. componentWillUnmount(){
  45. window.removeEventListener('scroll', this.handleScroll);
  46. }
  47.  
  48. render(){
  49. return(
  50. <div ref="moveMe" onMouseEnter={this.mouseEnter} onMouseLeave{this.mouseExit}
  51. className={`OnScrollComp ${this.state.open ? "visible" : ""}`} id={this.props.id}>
  52. {this.props.description} {this.props.link}
  53. </div>
  54. )
  55. }
  56. }
  57.  
  58. module.exports = OnScrollComponent;
  59.  
  60. .OnScrollComp {
  61. border-style: solid;
  62. border-color: black;
  63. border-width: thick;
  64. width: 600px;
  65. height: 300px;
  66. opacity: 0;
  67. transition: opacity 3s;
  68. pointer-events:none;
  69. }
  70.  
  71.  
  72.  
  73. .OnScrollComp.visible {
  74. opacity: 1;
  75. pointer-events:none;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement