A Pen by Rafa Garcés

Thumbnail
This awesome code was written by rafagarces, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright rafagarces ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  Rafa Garcés</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div style="width:100%;height:2500px;background-color:pink">
 <div class="NavigationButton menu_white">
    MENU
  </div>
  
  <div id='container_div' style="background-color:white;width:100%;height:200px;position:relative;top:50px">
  
  </div>

</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/rafagarces/a-pen-by-rafa-garcandxe9s-PJGmPW */
*{margin:0;}

.NavigationButton {
 position: fixed;
 top: 5%;
 right: 5%;
 z-index: 99999;
 font-family: neuzeit-grotesk, sans-serif;
 font-weight: 700;
 color: inherit;
}

.menu_white {
 background-color: transparent;
 color: white;
}

.menu_black {
 color: #000;
 background-color: lime;

}

/*Downloaded from https://www.codeseek.co/rafagarces/a-pen-by-rafa-garcandxe9s-PJGmPW */

$(document).ready(function(){
	$(window).scroll(function(){

  	var light_pos = $('#container_div').offset().top;
    var light_height = $('#container_div').height();
    var menu_pos = $('.NavigationButton').offset().top;
    var menu_height = $('.NavigationButton').height();
    var scroll = $(window).scrollTop();
    console.log('light',light_pos);
    console.log('menu',menu_pos);
    console.log('scroll',scroll);
    
    if((menu_pos + menu_height) > light_pos && menu_pos < (light_pos + light_height)) {
    	$('.NavigationButton').addClass('menu_black');
        $('.NavigationButton').removeClass('menu_white');
    }
    else {
    	$('.NavigationButton').removeClass('menu_black');
        $('.NavigationButton').addClass('menu_white');
    }
    
  })
})

Comments