Skip to content

Commit

Permalink
Update jquery.scrollme.js
Browse files Browse the repository at this point in the history
Added support for different easing functions
  • Loading branch information
nckprsn committed Jun 14, 2014
1 parent 4a42228 commit a575b7f
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions jquery.scrollme.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
effect.from = effect.element.data( 'from' );
effect.to = effect.element.data( 'to' );

if( effect.element.is( '[data-easing]' ) )
{
effect.easing = [ effect.element.data( 'easing' ) ];
}
else
{
effect.easing = easeout;
}

// Get animated properties

var properties = {};
Expand Down Expand Up @@ -185,7 +194,7 @@

// Apply easing

var scroll_eased = easing( scroll_relative );
var scroll_eased = effect.easing( scroll_relative );

// Get new value for each property

Expand Down Expand Up @@ -244,9 +253,9 @@
case 'translatex' : new_value = new_value.toFixed(0); break;
case 'translatey' : new_value = new_value.toFixed(0); break;
case 'translatez' : new_value = new_value.toFixed(0); break;
case 'rotatex' : new_value = new_value.toFixed(0); break;
case 'rotatey' : new_value = new_value.toFixed(0); break;
case 'rotatez' : new_value = new_value.toFixed(0); break;
case 'rotatex' : new_value = new_value.toFixed(1); break;
case 'rotatey' : new_value = new_value.toFixed(1); break;
case 'rotatez' : new_value = new_value.toFixed(1); break;
case 'scale' : new_value = new_value.toFixed(2); break;
default : break;
}
Expand All @@ -257,9 +266,29 @@
}

// ----------------------------------------------------------------------------------------------------
// Easing function (cubic in/out)
// Easing functions

// Linear
linear = function( x )
{
return x;
}

// Ease out (cubic)
easeout = function( x )
{
return x * x * x;
}

// Ease in (cubic)
easein = function( x )
{
x = 1 - x;
return 1 - ( x * x * x );
}

easing = function( x )
// Ease in/out (cubic)
easeinout = function( x )
{
if( x < 0.5 )
{
Expand Down

0 comments on commit a575b7f

Please sign in to comment.