parallax.coffee
868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#
# 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: