Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Adjusted spinner math to improve animation. Removed 16 type references. #214

Merged
merged 1 commit into from
Nov 17, 2015
Merged
Show file tree
Hide file tree
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
33 changes: 13 additions & 20 deletions src/components/Spinner/Spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ var fabric = fabric || {};

/**
* @param {HTMLDOMElement} target - The element the Spinner will attach itself to.
* @param {string} type - The type of spinner. Set this property to "sixteen" for sixteen dot version. The default is eight.
*/

fabric.Spinner = function(target, spinnerType) {
fabric.Spinner = function(target) {

var _target = target;
var _spinnerType = spinnerType || "eight";
var eightSize = 0.18;
var sixteenSize = 0.1;
var circleObjects = [];
var animationSpeed = 50;
var animationSpeed = 80;
var interval;
var spinner;
var numCircles;
var offsetSize;
var fadeIncrement = 0;

/**
* @function start - starts or restarts the animation sequence
Expand All @@ -37,7 +35,6 @@ fabric.Spinner = function(target, spinnerType) {
function start() {
interval = setInterval(function() {
var i = circleObjects.length;

while(i--) {
_fade(circleObjects[i]);
}
Expand All @@ -55,37 +52,33 @@ fabric.Spinner = function(target, spinnerType) {
//private methods

function _init() {
if(_spinnerType === "sixteen") {
offsetSize = sixteenSize;
numCircles = 16;
} else {
offsetSize = eightSize;
numCircles = 8;
}
offsetSize = eightSize;
numCircles = 8;
_createCirclesAndArrange();
_initializeOpacities();
start();
}

function _initializeOpacities() {
var i = 0;
var j = 2;
var opacity;
var increment = (1 / (numCircles));
fadeIncrement = (1 / (numCircles + 2));

for (i; i < numCircles; i++) {
var circleObject = circleObjects[i];
opacity = (increment * i);
opacity = (fadeIncrement * j++);
_setOpacity(circleObject.element, opacity);
}
}

function _fade(circleObject) {
var increment = (1 / numCircles) * 0.5;
var opacity = _getOpacity(circleObject.element) - increment;
var opacity = Math.round((_getOpacity(circleObject.element) - fadeIncrement) * 100) * 0.01;

if (opacity <= increment) {
opacity = 1;
if (opacity <= 0) {
opacity = 0.8;
}

_setOpacity(circleObject.element, opacity);
}

Expand Down Expand Up @@ -114,7 +107,7 @@ fabric.Spinner = function(target, spinnerType) {
} else {
spinner = _target;
}

var width = spinner.clientWidth;
var height = spinner.clientHeight;
var angle = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Spinner/Spinner.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

.ms-Spinner-circle {
position: absolute;
border-radius: 999px;
border-radius: 100px;
background-color: black;
opacity: 0;
}