Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. export default class NavbarComp extends Component {
  2. constructor() {
  3. super();
  4. this.state = {
  5. windowHight:"",
  6. navbarfix: ""
  7. };
  8. this.handleScroll = this.handleScroll.bind(this)
  9. }
  10.  
  11. getWindowHight(){
  12. let deviceWindow = document.getElementById('landing-section');
  13. let deviceWindowHight = window.getComputedStyle(deviceWindow).getPropertyValue('height');
  14.  
  15. console.log("from getinitiatlhight" + deviceWindowHight);
  16.  
  17. this.setState({
  18. windowHight: deviceWindowHight
  19. });
  20.  
  21. componentDidMount(){
  22. window.addEventListener('scroll', this.handleScroll);
  23. this.getWindowHight();
  24. }
  25.  
  26. handleScroll() {
  27. console.log("scrolll" + this.state.windowHight);
  28. if (window.pageYOffset >= this.state.windowHight) {
  29. console.log("fix");
  30. } else if (window.scrollY < this.state.windowHight) {
  31. console.log("unfix" );
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement