Created
December 12, 2018 18:44
-
-
Save romanoffs/8a8d16028cf2c157938115f9364cd043 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parallaxController; | |
!function() { | |
function t() { | |
for (var t = 1; t < arguments.length; t++) | |
for (var e in arguments[t]) | |
arguments[t].hasOwnProperty(e) && (arguments[0][e] = arguments[t][e]); | |
return arguments[0] | |
} | |
function e() { | |
var t = this | |
, e = { | |
multiplier: "0.2", | |
direction: "up", | |
positionType: "absolute" | |
}; | |
paralaxxed.length > 0 && parallaxate(t.paralaxxed, e), | |
scrollHandler() | |
} | |
parallaxController = this; | |
var s = !0; | |
this.paralaxxed = document.getElementsByClassName("parallaxy-animate"), | |
parallaxate = function(e, s) { | |
var n = e; | |
for (i = 0; i < n.length; i++) { | |
var r = JSON.parse(JSON.stringify(s)) | |
, o = JSON.parse(n[i].getAttribute("data-option")); | |
n[i].settings = t(r, o), | |
"relative" == o.positionType ? (n[i].initial_offset = parseInt(window.getComputedStyle(n[i], null).getPropertyValue("margin-top"), 10), | |
n[i].dataset.positionType = "relative") : (n[i].initial_offset = n[i].offsetTop, | |
n[i].dataset.positionType = "absolute"), | |
n[i].dataset = o.direction, | |
n[i].dataset.currentDelta = 0, | |
n[i].dataset.newDelta = 0 | |
} | |
} | |
, | |
scrollHandler = function() { | |
var t = window.pageYOffset; | |
for (i = 0; i < paralaxxed.length; i++) { | |
var e = paralaxxed[i].dataset.currentDelta | |
, n = 0 - t * paralaxxed[i].settings.multiplier; | |
if ("down" == paralaxxed[i].settings.direction && (n = 0 + t * paralaxxed[i].settings.multiplier), | |
"down" == paralaxxed[i].settings.direction) | |
; | |
else { | |
if (ismobile) | |
r = e - (e - n), | |
e && e < 0 && (paralaxxed[i].style.transform = "translateY(" + r + "px)"); | |
else { | |
var r = e - .08 * (e - n); | |
paralaxxed[i].style.transform = "translateY(" + r + "px) translateZ(0)", | |
paralaxxed[i].style.webkitTransform = "translateY(" + r + "px) translateZ(0)" | |
} | |
paralaxxed[i].dataset.currentDelta = r | |
} | |
} | |
s && window.requestAnimationFrame(scrollHandler) | |
} | |
, | |
pauseTween = function() { | |
s = !1 | |
} | |
, | |
restartTween = function() { | |
s = !0, | |
scrollHandler() | |
} | |
, | |
e() | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment