-1

Coding a static long-scroll website in node/express/backbone/stylus/dust.

We are going to have a ~400px header image that sits in a fixed position at the top of the page that then shrinks into a ~100px nav bar as you scroll downwards, then moves between a few states as you pass through various parts of the page.

What is the best way to code something like this? I know that's a very broad question, and that I don't have any code to substantiate this question, but I'm not sure what combination of CSS / scripting I would emplpy to make sure that the header shrinks, then persists, then moves between states.

RustyToms
  • 7,600
  • 1
  • 27
  • 36
fox
  • 5,569
  • 3
  • 16
  • 13
  • Are you using jQuery? – RustyToms Dec 15 '13 at 11:59
  • yup, jquery / lodash / backbone / dust / stylus on the client side. have a scaffolt setup that automatically gives me `index.coffee`, `style.styl`, and `template.dust` per backbone view, of which this is one. – fox Dec 15 '13 at 12:07

2 Answers2

1

Using jQuery, just set up an event handler for the scroll event (http://api.jquery.com/scroll/), then adjust the header's height or whatever else you need to do depending on what the current value of the scroll is. You can modify this code and throw it onto your page:

<script>

  $(window).scroll(function(){
    var $header = $('header');
    var scrollY = $(this).scrollTop();

    if (scrollY < 100){
      $header.css('height', '400px');
    } elseif(scrollY > 100 && scrollY < whatever){
      $header.css('height', '100px');
    } elseif( your next range here ){
      ...
    }

</script>
RustyToms
  • 7,600
  • 1
  • 27
  • 36
0

my first idea is to do the animation in javascript some pseudo code

body
   div long text
   div.navigation(data-navigation="shrink") at the beginning this div is outside of the screen are
   div other long text   
   div.navigation(data-navigation="changeElements") i am somewhere

   script.

$( window ).scroll(function() {
   // get all data-navigation elements
   var allNavigationElements = $('.navigation'), i;
   for(i = 0; i < allNavigationElements.length; i++){

here check are the elements in the view with Check if element is visible after scrolling

      if(inview){
         changeNavigationTo($element.data('navigation')
      }
   }
}
Community
  • 1
  • 1
tire0011
  • 1,048
  • 1
  • 11
  • 22