Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleaned up source

  • Loading branch information...
commit 4c6b22f6a23818aa11318d93857c4c1f86c82187 1 parent c45605f
Stephen Murphy authored

Showing 1 changed file with 10 additions and 12 deletions. Show diff stats Hide diff stats

  1. +10 12 js/parallaxer.js
22 js/parallaxer.js
@@ -3,12 +3,14 @@
3 3 this._stage = stage;
4 4 this._transitioning = false;
5 5 this._lastCursor = null;
  6 + this._xRange = 0.1; // Move at most 1/10 window width in x direction
  7 + this._yRange = 0.2; // Move at most 1/5 window height in y direction
6 8
7 9 window.addEventListener('devicemotion', this._onDeviceMove.bind(this), true);
8 10 window.addEventListener('mousemove', this._onMouseMove.bind(this), true);
9 11 }
10 12
11   - Parallaxer.TRANSITION = 'all .08s linear';
  13 + Parallaxer.TRANSITION = 'all .01s linear';
12 14 Parallaxer.TRANSITION_DIST_SQ = 200 * 200; // Minimum distance before applying a smooth transition effect
13 15
14 16 Parallaxer.prototype = {
@@ -17,7 +19,6 @@
17 19 },
18 20
19 21 _transition: function() {
20   - console.log('TRANSITION');
21 22 this._transitioning = true;
22 23 this._stage.style.WebkitTransition = Parallaxer.TRANSITION;
23 24 window.addEventListener('webkitTransitionEnd', this._onEndTransition.bind(this), true);
@@ -29,11 +30,12 @@
29 30 },
30 31
31 32 _onMouseMove: function(e) {
32   - var cursor = {x: e.clientX, y: e.clientY},
33   - win = {width: window.innerWidth, height: window.innerHeight},
34   - stage = {width: this._stage.offsetWidth, height: this._stage.offsetHeight};
  33 + var cursor = {x: e.clientX, y: e.clientY};
35 34
36   - if (this._lastCursor && !this._transitioning) {
  35 + if (!this._lastCursor) { // Transition to initial mouse coordinates
  36 + this._transition();
  37 + }
  38 + else if (!this._transitioning) { // Transition if distance between mouse events is large
37 39 var dx = cursor.x - this._lastCursor.x,
38 40 dy = cursor.y - this._lastCursor.y;
39 41
@@ -41,15 +43,11 @@
41 43 this._transition();
42 44 }
43 45 }
44   - else {
45   - this._transition();
46   - }
47 46
48   - var x = -(cursor.x / win.width - 0.5) * stage.width * 0.1,
49   - y = -(cursor.y / win.height - 0.5) * stage.height * 0.2;
  47 + var x = -(cursor.x / window.innerWidth - 0.5) * window.innerWidth * this._xRange,
  48 + y = -(cursor.y / window.innerHeight - 0.5) * window.innerHeight * this._yRange;
50 49
51 50 this._stage.style.WebkitTransform = 'translate(' + x + 'px,' + y + 'px)';
52   -
53 51 this._lastCursor = cursor;
54 52 }
55 53 };

0 comments on commit 4c6b22f

Please sign in to comment.
Something went wrong with that request. Please try again.