Skip to content

Instantly share code, notes, and snippets.

@Riveascore
Last active August 29, 2015 14:19
Show Gist options
  • Save Riveascore/5b82355ac983077f7823 to your computer and use it in GitHub Desktop.
Save Riveascore/5b82355ac983077f7823 to your computer and use it in GitHub Desktop.
Loading cube animation, wrote on paper first using shorthand, looks pretty funny when you quickly type it out
var $lC = $loadingObject.find('.loading-cube'),
sT = $(window).scrollTop(),
eOT = $thisOffset.top,
eH = $this.height(),
wH = $(window).height(),
cH = 25,
nCP;
eVH;
if(sT > eOT) {
if(eOT + cH > sT + wH) {
eVH = wH;
}
else {
eVH = eOT + eH + sT;
}
nCP = sT + eVH / 2 - cH / 2;
}
else {
eVH = sT + wH - eOT;
nCP = eVH / 2 - cH / 2
}
// Now, only change cube top when necessary
if(eH > eVH) {
$lC.offset({ top: nCP });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment