Skip to content
This repository was archived by the owner on Jan 24, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/skrollr.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
}
}

_precision = parseInt(options.precision, 10) || 10;

_edgeStrategy = options.edgeStrategy || 'set';

_listeners = {
Expand Down Expand Up @@ -356,6 +358,9 @@
//If this particular element should emit keyframe events.
var emitEvents = false;

//The interpolation precision for this particular element.
var precision = _precision;

//If we're reseting the counter, remove any old element ids that may be hanging around.
if(ignoreID && SKROLLABLE_ID_DOM_PROPERTY in el) {
delete el[SKROLLABLE_ID_DOM_PROPERTY];
Expand Down Expand Up @@ -403,6 +408,13 @@
continue;
}

//Global precision can be overwritten by the element attribute.
if(attr.name === 'data-precision') {
precision = parseInt(attr.value, 10);

continue;
}

var match = attr.name.match(rxKeyframeAttribute);

if(match === null) {
Expand Down Expand Up @@ -493,6 +505,7 @@
smoothScrolling: smoothScrollThis,
edgeStrategy: edgeStrategy,
emitEvents: emitEvents,
precision: precision,
lastFrameIndex: -1
};

Expand Down Expand Up @@ -684,6 +697,7 @@
_smoothScrolling = undefined;
_forceRender = undefined;
_skrollableIdCounter = 0;
_precision = undefined;
_edgeStrategy = undefined;
_isMobile = false;
_mobileOffset = 0;
Expand Down Expand Up @@ -1019,7 +1033,7 @@
progress = left.props[key].easing(progress);

//Interpolate between the two values
value = _calcInterpolation(left.props[key].value, right.props[key].value, progress);
value = _calcInterpolation(left.props[key].value, right.props[key].value, progress, skrollable.precision);

value = _interpolateString(value);

Expand Down Expand Up @@ -1297,7 +1311,7 @@
/**
* Calculates the new values for two given values array.
*/
var _calcInterpolation = function(val1, val2, progress) {
var _calcInterpolation = function(val1, val2, progress, precision) {
var valueIndex;
var val1Length = val1.length;

Expand All @@ -1313,7 +1327,7 @@

for(; valueIndex < val1Length; valueIndex++) {
//That's the line where the two numbers are actually interpolated.
interpolated[valueIndex] = val1[valueIndex] + ((val2[valueIndex] - val1[valueIndex]) * progress);
interpolated[valueIndex] = (val1[valueIndex] + ((val2[valueIndex] - val1[valueIndex]) * progress)).toFixed(precision);
}

return interpolated;
Expand Down Expand Up @@ -1739,6 +1753,8 @@
//The ID is the index in the _skrollables array.
var _skrollableIdCounter = 0;

var _precision;

var _edgeStrategy;


Expand Down