Sha256: dc2d88e46b7e5b1b7032ee6d37d0b6dfa16e3f6a76c0eb9e32e180c058775438

Contents?: true

Size: 1.13 KB

Versions: 26

Compression:

Stored size: 1.13 KB

Contents

smoothScroll = ->
  $('a[href*=#]').click ->
    anchor = $(this).attr('href').match(/#(.*)/)[1]
    target = $('a[name=' + anchor + ']')
    ran = false
    $('html, body').animate { scrollTop: target.offset().top - 60 }, 400, ->
      unless ran
        offset = this.scrollTop
        location.hash = anchor
        this.scrollTop = offset
      ran = true
    false

highlightNav = ->
  anchors = $('h2 a[name]')
  anchor_links = $('ul a')
  positions = anchors.map (i, item) ->
    $(item).offset().top

  anchors = $.makeArray(anchors).reverse()
  anchor_links = $.makeArray(anchor_links).reverse()
  positions = $.makeArray(positions).reverse()

  scrollHappened = ->
    anchor_index = null
    scroll_y = this.scrollY
    $.each positions, (i, item) ->
      if scroll_y >= item - 70
        anchor_index = i
        return false
    if anchor_index?
      $(anchor_links).removeClass 'selected'
      $(anchor_links[anchor_index]).addClass 'selected'
    if scroll_y < positions[positions.length - 1] - 70
      $(anchor_links).removeClass 'selected'

  $(window).scroll scrollHappened
  scrollHappened()

$ ->
  smoothScroll()
  highlightNav()

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
stasis-0.2.0 site/stasis.js.coffee
stasis-0.2.0.pre site/stasis.js.coffee
stasis-0.1.23 site/stasis.js.coffee
stasis-0.1.22 site/stasis.js.coffee
stasis-0.1.21 site/stasis.js.coffee
stasis-0.1.20 site/stasis.js.coffee
stasis-0.1.19 site/stasis.js.coffee
stasis-0.1.18 site/stasis.js.coffee
stasis-0.1.17 site/stasis.js.coffee
stasis-0.1.16 site/stasis.js.coffee
stasis-0.1.15 site/stasis.js.coffee
stasis-0.1.14 site/stasis.js.coffee
stasis-0.1.13 site/stasis.js.coffee
stasis-0.1.12 site/stasis.js.coffee
stasis-0.1.11 site/stasis.js.coffee
stasis-0.1.10 site/stasis.js.coffee
stasis-0.1.9 site/stasis.js.coffee
stasis-0.1.8 site/stasis.js.coffee
stasis-0.1.7 site/stasis.js.coffee
stasis-0.1.6 site/stasis.js.coffee