function position() {
    var pos = window.pageYOffset - 10 - containerStart;
    var dir = (pos > currentPos) ? +1 : -1;
    currentPos = pos;
    var sectionIndex = d3.bisect(sectionPositions, pos);
    sectionIndex = Math.min(sections.size() - 1, sectionIndex);


    // get the height of the window
    var height = window.innerHeight;

    // if we are scrolling down
    if((dir > 0)) {

      // is the index we think we are at on the screen?
      var onScreen = (sectionPositions[sectionIndex] < (pos + height));

      // if not, revert
      if(!onScreen) {
        console.log('keep current');
        sectionIndex = currentIndex;
      }
      // scrolling down
    } else {
      // is the index we think we are at below the screen?
      var belowScreen = (sectionPositions[sectionIndex] > (pos + height));


      // if so, bump it back
      if(belowScreen) {
        console.log('use prev');
        sectionIndex = Math.max(sectionIndex - 1, 0);
      }
    }

    if (currentIndex !== sectionIndex) {
      dispatch.active(sectionIndex);
      currentIndex = sectionIndex;
    }

    var prevIndex = Math.max(sectionIndex - 1, 0);
    var prevTop = sectionPositions[prevIndex];
    var progress = (pos - prevTop) / (sectionPositions[sectionIndex] - prevTop);
    dispatch.progress(currentIndex, progress);
  }
/**
   * position - get current users position.
   * if user has scrolled to new section,
   * dispatch active event with new section
   * index.
   *
   */
get current users position.
if user has scrolled to new section,
dispatch active event with new section
index.
get current users position . if user has scrolled to new section dispatch active event with new section index .
function position() {
    var pos = window.pageYOffset - 10 - containerStart;
    var dir = (pos > currentPos) ? +1 : -1;
    currentPos = pos;
    var sectionIndex = d3.bisect(sectionPositions, pos);
    sectionIndex = Math.min(sections.size() - 1, sectionIndex);
    var height = window.innerHeight;
    if((dir > 0)) {
      var onScreen = (sectionPositions[sectionIndex] < (pos + height));
      if(!onScreen) {
        console.log('keep current');
        sectionIndex = currentIndex;
      }
    } else {
      var belowScreen = (sectionPositions[sectionIndex] > (pos + height));
      if(belowScreen) {
        console.log('use prev');
        sectionIndex = Math.max(sectionIndex - 1, 0);
      }
    }
    if (currentIndex !== sectionIndex) {
      dispatch.active(sectionIndex);
      currentIndex = sectionIndex;
    }
    var prevIndex = Math.max(sectionIndex - 1, 0);
    var prevTop = sectionPositions[prevIndex];
    var progress = (pos - prevTop) / (sectionPositions[sectionIndex] - prevTop);
    dispatch.progress(currentIndex, progress);
  }
function position ( ) { var pos = window . pageYOffset - 10 - containerStart ; var dir = ( pos > currentPos ) ? + 1 : - 1 ; currentPos = pos ; var sectionIndex = d3 . bisect ( sectionPositions , pos ) ; sectionIndex = Math . min ( sections . size ( ) - 1 , sectionIndex ) ; var height = window . innerHeight ; if ( ( dir > 0 ) ) { var onScreen = ( sectionPositions [ sectionIndex ] < ( pos + height ) ) ; if ( ! onScreen ) { console . log ( 'keep current' ) ; sectionIndex = currentIndex ; } } else { var belowScreen = ( sectionPositions [ sectionIndex ] > ( pos + height ) ) ; if ( belowScreen ) { console . log ( 'use prev' ) ; sectionIndex = Math . max ( sectionIndex - 1 , 0 ) ; } } if ( currentIndex !== sectionIndex ) { dispatch . active ( sectionIndex ) ; currentIndex = sectionIndex ; } var prevIndex = Math . max ( sectionIndex - 1 , 0 ) ; var prevTop = sectionPositions [ prevIndex ] ; var progress = ( pos - prevTop ) / ( sectionPositions [ sectionIndex ] - prevTop ) ; dispatch . progress ( currentIndex , progress ) ; }
position - get current users position.
position - get current users position .
// get the height of the window // if we are scrolling down // is the index we think we are at on the screen? // if not, revert // scrolling down // is the index we think we are at below the screen? // if so, bump it back