summaryrefslogtreecommitdiffstats
path: root/bounds3/slider.js
diff options
context:
space:
mode:
authorDavid DeSandro <desandrocodes@gmail.com>2014-12-21 12:20:54 -0500
committerDavid DeSandro <desandrocodes@gmail.com>2014-12-21 12:20:54 -0500
commita3ff3a4a0684f77e7f3be9d0223aedd551cbeec4 (patch)
treee70f1d57be67b6a135538f2744ae660669dba2eb /bounds3/slider.js
parent9e326512d2fb3f6b1821d2ce9ad8a62b82c475ef (diff)
downloadflickity-dev-a3ff3a4a0684f77e7f3be9d0223aedd551cbeec4.zip
flickity-dev-a3ff3a4a0684f77e7f3be9d0223aedd551cbeec4.tar.gz
flickity-dev-a3ff3a4a0684f77e7f3be9d0223aedd551cbeec4.tar.bz2
remove sandbox/
Diffstat (limited to 'bounds3/slider.js')
-rw-r--r--bounds3/slider.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/bounds3/slider.js b/bounds3/slider.js
new file mode 100644
index 0000000..e245071
--- /dev/null
+++ b/bounds3/slider.js
@@ -0,0 +1,45 @@
+( function() {
+
+function Slider( x, y ) {
+ this.x = x;
+ this.y = y;
+ this.velocity = 0;
+ this.accel = 0;
+ this.friction = 0.15;
+}
+
+Slider.prototype.update = function() {
+ this.velocity += this.accel;
+ this.velocity *= ( 1 - this.friction );
+ this.x += this.velocity;
+ this.accel = 0;
+};
+
+Slider.prototype.applyForce = function( force ) {
+ this.accel += force;
+};
+
+
+Slider.prototype.getRestingPosition = function() {
+
+ var fFriction = 1 - this.friction;
+ var restingVelo = 0.07;
+ var ticks = getBaseLog( fFriction, restingVelo / Math.abs( this.velocity ) );
+ var frictionSum = ( Math.pow( fFriction, ticks + 1 ) - 1 ) / ( fFriction - 1 );
+ var restX = this.x + this.velocity * fFriction * frictionSum;
+
+ return {
+ x: restX,
+ frictionSum: frictionSum
+ };
+};
+
+
+function getBaseLog( a, b ) {
+ return Math.log( b ) / Math.log( a );
+}
+
+
+window.Slider = Slider;
+
+})();