Commit 67b37f97552ccdc28c2bdd49ea77d1289626c2df

Authored by Georg Hopp
1 parent a2d5f0f5

clean parallax js

... ... @@ -4,61 +4,33 @@
4 4 #
5 5 window.App ||= {}
6 6
7   -content_top = content_left = width_delta = height_delta = 0
8   -
9 7 App.init = ->
10   - $('a[href*=\\#]').each ->
11   - lpath = location.pathname.replace(/^\//,'')
12   - tpath = this.pathname.replace(/^\//,'')
13   - if lpath == tpath and
14   - location.hostname == this.hostname and
15   - this.hash.replace(/#/,'')
16   - $targetId = $(this.hash)
17   - $targetAnchor = $('[name=' + this.hash.slice(1) + ']')
18   - $target = if $targetId.length
19   - $targetId
20   - else
21   - if $targetAnchor.length
22   - $targetAnchor
23   - else
24   - false
25   -
26   - if $target
27   - targetOffset = $target.offset().top
28   -
  8 + this.$slides = $('.section')
  9 + this.$menu = $("#nav a")
  10 + this.section = 0
  11 + this.$menu.each ->
  12 + $target = $(this.hash)
  13 + if $target.length
29 14 $(this).click ->
30   - $('html, body').animate({scrollTop: targetOffset}, 1000)
  15 + $('html, body').animate({scrollTop: $target.offset().top}, 1000)
31 16 return false
32 17
33 18 App.scroll = ->
  19 + if not this.$slides
  20 + return 0
34 21 v_scroll = $(document).scrollTop()
35   - section = Math.floor(v_scroll / $(window).innerHeight())
36   - [section, section+1].forEach (section) ->
37   - bg_pos = -((v_scroll-(section*$(window).innerHeight()))/2)
38   - section_element = $($(".section")[section])
39   - if section_element and section_element.css("background-image") != "none"
40   - content = section_element.find(".content")
41   - content.css("display", "none")
42   - section_element.css(
43   - "background-position",
44   - "center " + bg_pos + "px")
45   - content.css("display", "block")
46   -
47   -App.scroll2 = ->
48   - v_scroll = $(document).scrollTop()
49   - section = 0
50   - for value, index in $(".section")
51   - if v_scroll >= $(value).offset().top
52   - section = index
53   - if not $($("#nav a")[section]).hasClass('active')
54   - $("#nav a").removeClass("active")
55   - $($("#nav a")[section]).addClass('active')
  22 + for slide,i in this.$slides
  23 + if v_scroll >= slide.offsetTop
  24 + this.section = i
  25 + if not $(this.$menu[this.section]).hasClass('active')
  26 + $(this.$menu).removeClass('active')
  27 + $(this.$menu[this.section]).addClass('active')
56 28
57 29 $(document).on "page:change", ->
58 30 App.init()
59 31
60 32 $(window).on "scroll", ->
61   - App.scroll2()
  33 + App.scroll()
62 34
63 35 $(document).ready ->
64 36 App.init()
... ...
Please register or login to post a comment