You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
48 lines
1.3 KiB
#
|
|
# 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 ||= {}
|
|
|
|
content_top = content_left = width_delta = height_delta = 0
|
|
|
|
App.init = ->
|
|
$('a[href*=\\#]').each ->
|
|
if location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') and location.hostname == this.hostname and this.hash.replace(/#/,'')
|
|
$targetId = $(this.hash)
|
|
$targetAnchor = $('[name=' + this.hash.slice(1) + ']')
|
|
$target = if $targetId.length
|
|
$targetId
|
|
else
|
|
if $targetAnchor.length
|
|
$targetAnchor
|
|
else
|
|
false
|
|
|
|
if $target
|
|
targetOffset = $target.offset().top
|
|
|
|
$(this).click ->
|
|
$("#nav li a").removeClass("active")
|
|
$(this).addClass('active')
|
|
$('html, body').animate({scrollTop: targetOffset}, 1000)
|
|
return false
|
|
|
|
App.scroll = ->
|
|
v_scroll = $(document).scrollTop()
|
|
section = Math.floor(v_scroll / $(window).innerHeight())
|
|
[section, section+1].forEach (section) ->
|
|
bg_pos = -((v_scroll-(section*$(window).innerHeight()))/2)
|
|
section_element = $($(".section")[section])
|
|
if section_element and section_element.css("background-image") != "none"
|
|
section_element.css(
|
|
"background-position",
|
|
"center " + bg_pos + "px")
|
|
|
|
$(document).on "page:change", ->
|
|
App.init()
|
|
|
|
$(window).on "scroll", ->
|
|
App.scroll()
|
|
|
|
# vim: set ts=2 sw=2:
|