javascript - CSS based on viewport height -
goldman sachs has pretty cool webpage here. interests me page when scroll down, header appearing, - depending on section you're @ - has more of squares turn white blue. wondering (because can't seem find answer in code), how made scrollbar appear seemingly out of blue (pun not intended), how squares turn white blue depending on over page.
the common way detecting position of scrollbar javascript. i've used jquery library demo.
here's code (merely illustration purpose!)
$(window).scroll(function (event) { var numofbuttons = 4; var scroll = $(window).scrolltop(); var heightcontainer = $(".container").height(); console.log('scrollpos', scroll); if(scroll > heightcontainer/ numofbuttons){ $(".header .button:nth-child(2)").addclass('act'); }else{ $(".header .button:nth-child(2)").removeclass('act'); } if(scroll > (heightcontainer/ numofbuttons)*2){ $(".header .button:nth-child(3)").addclass('act'); }else{ $(".header .button:nth-child(3)").removeclass('act'); } if(scroll > (heightcontainer/ numofbuttons)*3){ $(".header .button:nth-child(4)").addclass('act'); }else{ $(".header .button:nth-child(4)").removeclass('act'); } });
.header{ height:50px; background-color:blue; color:white; position:fixed; top:0; left:0; width:100% } .button{ display:inline-block; width:10px; height:10px; background-color:white; border-radius:20px; } .button.act{ background-color:red; } h1{ margin-top:60px; } .container{ height:4000px; background:url("http://www.planwallpaper.com/static/images/518164-backgrounds.jpg"); }
<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> <h1>scroll demo</h1> <div class="header"> <div class="button act"></div> <div class="button"></div> <div class="button"></div> <div class="button"></div> </div> <div class="container"><div id="mydiv"></div> </div> </body> </html>
Comments
Post a Comment