Permalink
Browse files

added smoothing option

  • Loading branch information...
1 parent 13b6e4b commit fac7c8d2500ba671bf6760f906c9d2a2390cdbd4 Stephen Murphy committed Jul 25, 2013
Showing with 13 additions and 9 deletions.
  1. +1 −0 README.md
  2. +12 −9 parallaxer.js
View
@@ -58,6 +58,7 @@ __Arguments__
* options.xRange - Maximum distance to scroll in x direction
* options.yRange - Maximum distance to scroll in y direction
* options.invert - Invert the direction of travel in both directions
+ * options.smoothing - Use transitions if distance between mouse coordinates is large (default false).
__Example__
View
@@ -8,6 +8,7 @@
y: opts.yRange || Parallaxer.Y_RANGE
};
this._inversion = opts.invert ? -1 : 1;
+ this._smoothing = opts.smoothing || false;
this._transitioning = false;
this._lastCursor = null;
@@ -77,17 +78,19 @@
},
_onMouseMove: function(e) {
- if (!this._lastCursor) { // Transition to initial mouse coordinates
- this._transition();
- }
- else if (!this._transitioning) {
- var dx = e.clientX - this._lastCursor.x,
- dy = e.clientY - this._lastCursor.y;
-
- // Transition if distance between mouse events is large
- if (dx * dx + dy * dy > Parallaxer.TRANSITION_DIST_SQ) {
+ if (this._smoothing) {
+ if (!this._lastCursor) { // Transition to initial mouse coordinates
this._transition();
}
+ else if (!this._transitioning) {
+ var dx = e.clientX - this._lastCursor.x,
+ dy = e.clientY - this._lastCursor.y;
+
+ // Transition if distance between mouse events is large
+ if (dx * dx + dy * dy > Parallaxer.TRANSITION_DIST_SQ) {
+ this._transition();
+ }
+ }
}
var x = this._inversion * (2 * e.clientX / window.innerWidth - 1.0) * this._range.x,

0 comments on commit fac7c8d

Please sign in to comment.