Skip to content

Instantly share code, notes, and snippets.

@davidlwatsonjr
Created December 14, 2012 04:40
Show Gist options
  • Save davidlwatsonjr/4282728 to your computer and use it in GitHub Desktop.
Save davidlwatsonjr/4282728 to your computer and use it in GitHub Desktop.
The beginnings of the drunken-scroller stellar.js plugin.
$.stellar.positionProperty.stagger = {
setTop: function ($element, newTop, originalTop) {
var $elementCoords = $element.position();
var stellarScrollRatio = parseFloat($element.data('stellar-ratio'));
var direction = 'top';
var originalPosition = originalTop;
var currentPosition = $elementCoords.top;
var magnitude = newTop - originalTop;
if ($element.data('stellar-swap-horizontal-and-vertical') == true) {
if ($element.data('stellar-scroll-horizontal') == false) {
return false;
}
direction = 'left';
originalPosition = parseInt($element.data('stellar-starting-left'), 10);
currentPosition = $elementCoords.left;
magnitude = magnitude * -1;
} else {
if ($element.data('stellar-scroll-vertical') == false) {
return false;
}
}
if ('undefined' !== typeof $element.data('stellar-after-in-position')) {
if (((stellarScrollRatio > 1) &&
(magnitude > 0)) ||
((stellarScrollRatio < 1) &&
(magnitude < 0))) {
switch ($element.data('stellar-after-in-position')) {
case 'stay':
magnitude = 0;
break;
case 'reverse':
magnitude = magnitude * -1;
break;
default:
break;
}
}
}
$element.css(direction, originalPosition + magnitude);
},
setLeft: function ($element, newLeft, originalLeft) {
var $elementCoords = $element.position();
var stellarScrollRatio = parseFloat($element.data('stellar-ratio'));
var direction = 'left';
var originalPosition = originalLeft;
var currentPosition = $elementCoords.left;
var magnitude = newLeft - originalLeft;
if ($element.data('stellar-swap-horizontal-and-vertical') == true) {
if ($element.data('stellar-scroll-vertical') == false) {
return false;
}
direction = 'top';
originalPosition = parseInt($element.data('stellar-starting-top'), 10);
currentPosition = $elementCoords.top;
magnitude = magnitude * -1;
} else {
if ($element.data('stellar-scroll-horizontal') == false) {
return false;
}
}
if ($element.data('stellar-after-in-position')) {
if (((stellarScrollRatio > 1) &&
(magnitude > 0)) ||
((stellarScrollRatio < 1) &&
(magnitude < 0))) {
switch ($element.data('stellar-after-in-position')) {
case 'stay':
magnitude = 0;
break;
case 'reverse':
magnitude = magnitude * -1;
break;
default:
break;
}
}
}
$element.css(direction, originalPosition + magnitude);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment