Skip to content

Instantly share code, notes, and snippets.

@mimiflynn
Created December 15, 2015 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mimiflynn/cba18ba79e79dd340a26 to your computer and use it in GitHub Desktop.
Save mimiflynn/cba18ba79e79dd340a26 to your computer and use it in GitHub Desktop.
var velocity = function (el, header) {
var wWidth = $(window).width(),
spacing = $(header).height(),
offset = $(el).offset();
// Create consistent velocity!
// Perfect velocity = 2550px per 3000milliseconds = .85 you know, since v = d/t
var current = window.pageYOffset;
// get current position
var movement = offset.top - spacing;
// set distance for movement from the top minus space for header
var distance = current - movement;
// get distance from current position
distance = Math.abs(distance);
// can't use negative numbers
var speed = distance / 1.105;
// 1.105 is the velocity!
return {
speed: speed,
movement: movement
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment