parallax.coffee 868 Bytes
#
# OK, this is not really a parallax... I just want to see my content move
# somewhat faster than the background... hey, ho, let's go
#
window.App ||= {}

App.init = ->
	this.$slides = $('.section')
	this.$menu = $("#nav a")
	this.section = 0
	this.$menu.each ->
		$target = $(this.hash)
		if $target.length
			$(this).click ->
				$('html, body').animate({scrollTop: $target.offset().top}, 1000)
				return false

App.scroll = ->
	if not this.$slides
		return 0
	v_scroll = $(document).scrollTop()
	for slide,i in this.$slides
		if v_scroll >= slide.offsetTop
			this.section = i
	if not $(this.$menu[this.section]).hasClass('active')
		$(this.$menu).removeClass('active')
		$(this.$menu[this.section]).addClass('active')

$(document).on "page:change", ->
	App.init()

$(window).on "scroll", ->
	App.scroll()

$(document).ready ->
	App.init()

# vim: set ts=2 sw=2: